fix: didn't count failure in allow method with breaker algorithm (#4008)

This commit is contained in:
Kevin Wan
2024-03-16 22:19:36 +08:00
committed by GitHub
parent 0449450c64
commit bbce95e7e1
2 changed files with 5 additions and 3 deletions

View File

@@ -31,9 +31,10 @@ type (
Name() string
// Allow checks if the request is allowed.
// If allowed, a promise will be returned, the caller needs to call promise.Accept()
// on success, or call promise.Reject() on failure.
// If not allow, ErrServiceUnavailable will be returned.
// If allowed, a promise will be returned,
// otherwise ErrServiceUnavailable will be returned as the error.
// The caller needs to call promise.Accept() on success,
// or call promise.Reject() on failure.
Allow() (Promise, error)
// Do runs the given request if the Breaker accepts it.

View File

@@ -52,6 +52,7 @@ func (b *googleBreaker) accept() error {
func (b *googleBreaker) allow() (internalPromise, error) {
if err := b.accept(); err != nil {
b.markFailure()
return nil, err
}