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.

Support `@CircuitBreaker` on suspend functions (including `suspend fun` fallback methods) in Spring Boot 2

See original GitHub issue

Resilience4j version: 1.7.1 Java version: 16 kotlin version: 1.5.30

@CircuitBreaker does not work with bean suspend functions even when it boasts Kotlin Coroutines support.

First, FallbackMethod.create(...) will always fail to find the fallback method because of how kotlin inserts a kotlin.coroutines.Continuation<T> as the last parameter of suspend functions. This is illustrated below.

@Service class MyBean {

  @CircuitBreaker("breakerName", fallbackMethod = "aFallbackMethod")
  suspend fun aMethod(aParam: String): String { ... }
  
  suspend fun aFallbackMethod(theParam: String, error: Throwable): String { ... }
}

For the above bean the runtime method signatures are

aMethod(String, Continuation): Object & aFallbackMethod(String, Throwable, Continuation): Object

which is why the fallback method cannot be determined, because the throwable is not the last parameter in the fallback function.

Also, being a suspend function, its inherently asynchronous and needs to be explicitly handled (or wrapped somehow) inside of CircuitBreakerAspect to function correctly

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
efemoneycommented, Oct 20, 2021

@RobWin Sounds good. I will open a PR soon for this.

0reactions
RobWincommented, Dec 6, 2022

No

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started | Spring Cloud Circuit Breaker Guide
This guide walks you through the process of applying circuit breakers to potentially-failing method calls using Spring Cloud Circuit Breaker.
Read more >
Circuit Breaking In Spring Cloud Gateway With Resilience4J
I'm going to show some sample scenarios of using Spring Cloud Circuit Breaker with Spring Cloud Gateway including a fallback pattern.
Read more >
How to combine CircuitBreaker with TimeLimiter and Bulkhead?
Have a circuit-breaker to protect the dependency when it's struggling; Limit the time the call can run. The service has an SLA and...
Read more >
Fallbacks with Spring Cloud Feign - Arnold Galovics
Since the Spring Cloud OpenFeign package doesn't support fallbacks by default, we have to involve another Spring Cloud package, circuitbreaker.
Read more >
City Library — An advanced guide to Circuit Breakers in Kotlin
In this section, we'll go through unit tests I've designed in order to analyze the specific properties of circuit breakers. We will check...
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