From 4fb0de2a6983bad3dd7bb1aa34657a50f0edc16b Mon Sep 17 00:00:00 2001 From: Travis Bischel Date: Tue, 24 Aug 2021 20:34:26 -0600 Subject: [PATCH] isRetriableBrokerErr: opt in net.ErrClosed, restructure net.ErrClosed implements temporary, and returns false. We need to evaluate ErrClosed before we check the temporary status. --- pkg/kgo/errors.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/pkg/kgo/errors.go b/pkg/kgo/errors.go index 231cccba..f63f1fa2 100644 --- a/pkg/kgo/errors.go +++ b/pkg/kgo/errors.go @@ -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 }