spring-cloud / spring-cloud-circuitbreaker

Spring Cloud Circuit Breaker API and Implementations
Apache License 2.0
335 stars 110 forks source link

why circuitbreaker recordexceptions attribute in spring cloud does not work? #66

Closed luguoji closed 3 years ago

luguoji commented 4 years ago

1

I am using cloud gateway circuitbreaker, find the method Mono run(Mono toRun, Function<Throwable, Mono> fallback) only handle TimeoutException, the recordexceptions of CircuitBreakerConfig does not work,such as java.lang.RuntimeException。Looks like it is bug。

ryanjbaxter commented 4 years ago

The code is there specifically in the reactive case because we are using Project Reactor's timeout api and R4J will not handle a timeout from reactor like it would if we were using an R4J timeout.

luguoji commented 4 years ago

Thanks for your reply. When I used cloud gateway, the downstream uri has runtimexception, but R4J does not CircuitBreak. I try to config the RecordExceptions,add java.lang.RuntimeException. But it still doesn't work. I hope I can get your help and support. Thanks you very much.

luguoji commented 4 years ago

Currently, only TimeOutException trigger CircuitBreak, other exceptions does not work. Is it a problem?

landyking commented 4 years ago

Currently, only TimeOutException trigger CircuitBreak, other exceptions does not work. Is it a problem?

Other exceptions also can be recorded. See here io.github.resilience4j.reactor.circuitbreaker.operator.CircuitBreakerSubscriber#hookOnError. If you want the circuit breaker to work with the response status code, you can write a gateway filter to check the status code and throw custom exceptions. Then CircuitBreakerSubscriber#hookOnError will catch and record the failure request.

ryanjbaxter commented 3 years ago

Is the downstream service returning a specific status code when the exception is thrown?

spring-cloud-issues commented 3 years ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-cloud-issues commented 3 years ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

beerathlete commented 2 years ago

Currently, only TimeOutException trigger CircuitBreak, other exceptions does not work. Is it a problem?

Other exceptions also can be recorded. See here io.github.resilience4j.reactor.circuitbreaker.operator.CircuitBreakerSubscriber#hookOnError. If you want the circuit breaker to work with the response status code, you can write a gateway filter to check the status code and throw custom exceptions. Then CircuitBreakerSubscriber#hookOnError will catch and record the failure request.

Hello! I had same problem like author has, and I had follow this advice and it was very helpful for me. But now circuitbreaker's fallback method is called every time when downstream service returning http status code exception, even ciruitbreaker state is closed. Is it possible to use this way to intercept not only TimeOutException and call fallback method only when circuitbreaker is open?

ryanjbaxter commented 2 years ago

Please open a separate issue and provide a sample