-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confusion about ErrTooManyRequests error #30
Comments
If you call |
AFAIK |
Hi @tegaralaga You can reproduce the func TestTooManyRequests(t *testing.T) {
customCB.setState(StateHalfOpen, time.Now())
// 3 consecutive successes
succeedLater(customCB, time.Duration(1000)*time.Millisecond)
succeedLater(customCB, time.Duration(1000)*time.Millisecond)
succeedLater(customCB, time.Duration(1000)*time.Millisecond)
time.Sleep(time.Duration(100) * time.Millisecond)
assert.Equal(t, Counts{3, 0, 0, 0, 0}, customCB.counts)
assert.Equal(t, succeed(customCB), ErrTooManyRequests)
} |
I'm using the "two steps" circuit breaker and is very easy to get the The state machine stuck by the condition mentioned in this issue: Maybe this is a issue when use the "two steps" feature, but probably a public function to force a state or reset the counters would be helpful to handle this behavior. |
Hi,
Thanks a lot for your library, it's simple, yet powerful! :)
Could you please clarify one confusion I have about ErrTooManyRequests error? I don't quite understand from the code when this error could happen.
I see the
if state == StateHalfOpen && cb.counts.Requests >= cb.maxRequests
condition in thebeforeRequest()
method but from the rest of the code it doesn't look like it could ever be met. This is because we either get enough consecutive requests to trip circuit to close with this conditionif cb.counts.ConsecutiveSuccesses >= cb.maxRequests { cb.setState(StateClosed, now) }
or we go back to open state because of a single failure inonFailure()
. Or did I misunderstand something?The text was updated successfully, but these errors were encountered: