danielfm / pybreaker

Python implementation of the Circuit Breaker pattern.
BSD 3-Clause "New" or "Revised" License
512 stars 74 forks source link

Wrapped function is called twice during successful call in open state #8

Closed jstordeur closed 7 years ago

jstordeur commented 7 years ago

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.

danielfm commented 7 years ago

Nice catch! Thanks! 😄