resilience4j / resilience4j

Resilience4j is a fault tolerance library designed for Java8 and functional programming
Apache License 2.0
9.72k stars 1.33k forks source link

CircuitBreaker not going in half open state in server #2167

Open torrtuga opened 4 months ago

torrtuga commented 4 months ago

Resilience4j version: resilience4j-circuitbreaker-2.1.0.jar

Java version: JDK17

I have circuitbreaker implemented in my springboot application. I have used following dependency:

implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j' And I have following properties configured for my testing:

resilience4j:
  circuitbreaker:
    instances:
      myEventCircuitBreaker:
        minimum-number-of-calls: 6
        failure-rate-threshold: 80
        automatic-transition-from-open-to-half-open-enabled: true
        wait-duration-in-open-state: 300s
        permitted-number-of-calls-in-half-open-state: 4
        sliding-window-size: 1000
        sliding-window-type: count_based

When I test in my local it works fine, where in case of exception after 6 events, circuit is opened. And after 300seconds (5 minutes) circuitbreaker goes in half open state.

I have following logs configured:

@Slf4j
@Configuration
public class CircuitBreakerConfig {

    private final BindingsLifecycleController bindingsLifecycleController;

    public CircuitBreakerConfig(CircuitBreakerRegistry circuitBreakerRegistry, BindingsLifecycleController bindingsLifecycleController) {
        this.bindingsLifecycleController = bindingsLifecycleController;
        CircuitBreaker circuitBreaker = circuitBreakerRegistry.circuitBreaker("myEventCircuitBreaker");
        circuitBreaker.getEventPublisher()
            .onStateTransition(this::handleStateTransition);
    }

    private void handleStateTransition(CircuitBreakerOnStateTransitionEvent event) {
        String bindingName = "stockEventConsumer-in-0";
        switch (event.getStateTransition().getToState()) {
            case OPEN:
                log.info("circuitbreaker state:: open");
                bindingsLifecycleController.changeState(bindingName, State.PAUSED);
                break;
            case HALF_OPEN:
                log.info("circuitbreaker state:: half_open");
                bindingsLifecycleController.changeState(bindingName, State.RESUMED);
                break;
            case CLOSED:
                log.info("circuitbreaker state:: closed");
                bindingsLifecycleController.changeState(bindingName, State.RESUMED);
                break;
            default:
                log.error("circuitbreaker unknown state");
        }
    }
}

The issue what I am facing is when I deploy my code in my dev/ppe environment, after 6 events with exception I am getting circuit open log.

But after that its not moving to half open state, and I don't see any logs from the configuration. The circuitbreaker remains open infinitely without going to half open state.

torrtuga commented 4 months ago

@RobWin @Romeh Can you please have a look

RobWin commented 4 months ago

Hi, can you update to 2.2.0 and check again?