Skip to content

Commit

Permalink
isRetriableBrokerErr: opt in net.ErrClosed, restructure
Browse files Browse the repository at this point in the history
net.ErrClosed implements temporary, and returns false. We need to
evaluate ErrClosed before we check the temporary status.
  • Loading branch information
twmb committed Aug 25, 2021
1 parent 0d01f74 commit 4fb0de2
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions pkg/kgo/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,25 @@ func isRetriableBrokerErr(err error) bool {
if errors.As(err, &se) {
return true
}
var tempErr interface{ Temporary() bool }
if errors.As(err, &tempErr) {
return tempErr.Temporary()
}

// EOF can be returned if a broker kills a connection unexpectedly, and
// we can retry that.
if errors.Is(err, io.EOF) {
// we can retry that. Same for ErrClosed.
if errors.Is(err, net.ErrClosed) || errors.Is(err, io.EOF) {
return true
}
switch err {
case errChosenBrokerDead,
errCorrelationIDMismatch:
// We could have chosen a broker, and then a concurrent metadata update
// could have removed it.
if errors.Is(err, errChosenBrokerDead) {
return true
}
// We really should not get correlation mismatch, but if we do, we can
// retry.
if errors.Is(err, errCorrelationIDMismatch) {
return true
}
var tempErr interface{ Temporary() bool }
if errors.As(err, &tempErr) {
return tempErr.Temporary()
}
return false
}

Expand Down

0 comments on commit 4fb0de2

Please sign in to comment.