When the circuit breaker is open:
cb.call() delegates to CircuitOpenState.call() which is not implemented so the parent CircuitBreakerState.call() is called.
This function calls CircuitOpenState.before_call() and then call the wrapped function.
CircuitOpenState.before_call() switch the state of the CB to half open and then calls cb.call(), which in turn delegates to CircuitHalfOpenState.call() which is not implemented so we go back to CircuitBreakerState.call() which eventually calls the wrapped function a second time (from a timeline perspective this is actually the first call)
I updated a testcase to illustrate the issue and propose a solution.
When the circuit breaker is open: cb.call() delegates to CircuitOpenState.call() which is not implemented so the parent CircuitBreakerState.call() is called. This function calls CircuitOpenState.before_call() and then call the wrapped function.
CircuitOpenState.before_call() switch the state of the CB to half open and then calls cb.call(), which in turn delegates to CircuitHalfOpenState.call() which is not implemented so we go back to CircuitBreakerState.call() which eventually calls the wrapped function a second time (from a timeline perspective this is actually the first call)
I updated a testcase to illustrate the issue and propose a solution.