4

Sometimes I can see a CallNotPermittedException with a message that says the circuit breaker is in HALF_OPEN state. But I don't understand how does it work in that state. I've written a test with a mock server where I have permittedNumberOfCallsInHalfOpenState=2 Then I enqueue 3 calls with a delay (3 seconds) and call, next call will fail with CallNotPermittedException and HALF_OPEN message. But if I wait the 3 seconds (enough for the calls to finish) and I do the next call, the CB is now in closed state. how's the transition from HALF_OPEN to another state ? does it wait for a time? or just "permittedNumberOfCallsInHalfOpenState" to finish ? then why I have to make 3 calls and not 2 ?

I'm using version 1.5

alegorth
  • 51
  • 1
  • 3

1 Answers1

10

The CircuitBreaker rejects calls with a CallNotPermittedException when it is OPEN. After a wait time duration has elapsed, the CircuitBreaker state changes from OPEN to HALF_OPEN and permits a configurable number of calls to see if the backend is still unavailable or has become available again. Further calls are rejected with a CallNotPermittedException, until all permitted calls have completed. If the failure rate or slow call rate is then equal or greater than the configured threshold, the state changes back to OPEN. If the failure rate and slow call rate is below the threshold, the state changes back to CLOSED.

That means if you have 3 concurrent calls in HALF_OPEN state, two are permitted and 1 is rejected.

But if 2 calls are successful before the third call is executed, the CircuitBreaker transitions to CLOSED and does permit the third call.

Robert Winkler
  • 1,734
  • 9
  • 8