question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Timelimiter Annotation not working (in SpringBoot Application)

See original GitHub issue

Resilience4j version: 1.7.0

Java version: 16.0.1

I had used the timelimiter annotation with timeout duration as 5 sec in “application.yml”. I was basically testing and trying out all the patterns in resilience 4j , all of them worked fine except the timelimiter. To test it, I had called a thread.sleep for 10 sec and still the result was being printed and the fallBackMethod doesn’t get called.

Here’s the snippet where annotation was done.

  @TimeLimiter(name="Time",fallbackMethod="fallBackMethod")
    public CompletableFuture<ResponseEntity<?>> listAllAvailableBooks() {
    	
    	List<Book> books=BRepository.findByPersonId(null);
    	try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        if(books.size()>0) {
        	return CompletableFuture.completedFuture(new ResponseEntity<>(books,HttpStatus.OK));
        }
        else {
        	return CompletableFuture.completedFuture(new ResponseEntity<>("No Books Available Now",HttpStatus.OK));
        }
    }
public CompletableFuture<ResponseEntity<?>> fallBackMethod(Exception e) {
    	System.out.println("Here time limit exceed\n");
    	return CompletableFuture.completedFuture(new ResponseEntity<>(e.getMessage(),HttpStatus.OK));
    }

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
RobWincommented, Jun 18, 2021
  @Bulkhead(name = BACKEND_A, type = Type.THREADPOOL)
  @TimeLimiter(name = BACKEND_A)
  @CircuitBreaker(name = BACKEND_A)
    public CompletableFuture<String> futureTimeout() {
        Try.run(() -> Thread.sleep(5000));
        return CompletableFuture.completedFuture("Hello World from backend A");
    }

The decoration is as follows:

CircuitBreaker ( TimeLimiter ( BulkHead ( method ( ) ) ) )

  1. Method is invoked in a Thread Pool.
  2. TimeLimiter limits the time of the thread, but the CompletableFuture is not/cannot be cancelled.
  3. CircuitBreaker records exceptions.
0reactions
nikhil-sardacommented, Jun 18, 2021

Thank you so much for the help. I am closing the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Timeouts with Spring Boot and Resilience4j - Reflectoring
Continuing the Resilience4j journey, this article on Spring Boot TimeLimiter shows when and how to use it to build resilient applications.
Read more >
SpringBoot Resilience4j Timelimiter | Timelimiter pattern
You will learn how we can build applications using Resilience4j- Timelimiter implementation in Spring Boot.
Read more >
spring test - How to run the SpringBootTest with only a single ...
I would like to run an integration test of a single bean with resilience4j annotated method in a spring boot app.
Read more >
Guide to Resilience4j With Spring Boot - Baeldung
Learn how to use the Resilience4j library with a simple Spring Boot application.
Read more >
Getting Started - resilience4j
Configuration. You can configure your CircuitBreaker, Retry, RateLimiter, Bulkhead, Thread pool bulkhead and TimeLimiter instances in Spring Boot's application.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found