Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions circuitbreaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,23 @@ func (cb *Breaker) CallContext(ctx context.Context, circuit func() error, timeou
}
}

if err != nil {
if ctx.Err() != context.Canceled {
if err == nil {
cb.Success()
return nil
}

switch ctx.Err() {
case context.Canceled:
case context.DeadlineExceeded:
// If the breaker timed out as well, report that,
// otherwise consider it "neutral".
if err == ErrBreakerTimeout {
cb.Fail()
}
return err
default:
cb.Fail()
}

cb.Success()
return nil
return err
}

// state returns the state of the TrippableBreaker. The states available are:
Expand Down
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func (c *HTTPClient) Do(req *http.Request) (*http.Response, error) {
var resp *http.Response
var err error
breaker := c.breakerLookup(req.URL.String())
err = breaker.Call(func() error {
ctx := req.Context()
err = breaker.CallContext(ctx, func() error {
resp, err = c.Client.Do(req)
return err
}, c.timeout)
Expand Down