From bbce95e7e1e20ad1756305bad818c671c069ed7a Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Sat, 16 Mar 2024 22:19:36 +0800 Subject: [PATCH] fix: didn't count failure in allow method with breaker algorithm (#4008) --- core/breaker/breaker.go | 7 ++++--- core/breaker/googlebreaker.go | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/breaker/breaker.go b/core/breaker/breaker.go index 3da681cdf..a53aca5c1 100644 --- a/core/breaker/breaker.go +++ b/core/breaker/breaker.go @@ -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. diff --git a/core/breaker/googlebreaker.go b/core/breaker/googlebreaker.go index f58566b03..462729568 100644 --- a/core/breaker/googlebreaker.go +++ b/core/breaker/googlebreaker.go @@ -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 }