Skip to content

Commit a995b1b

Browse files
committedNov 15, 2022
kgo broker: retry sasl auth failures during reauthentication
Perhaps something weird is happening on the broker. We will retry a request once, on a new connection.
1 parent 6bbe188 commit a995b1b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed
 

‎pkg/kgo/broker.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ start:
282282
func (b *broker) handleReq(pr promisedReq) {
283283
req := pr.req
284284
var cxn *brokerCxn
285+
var retriedOnNewConnection bool
286+
start:
285287
{
286288
var err error
287289
if cxn, err = b.loadConnection(pr.ctx, req); err != nil {
@@ -353,11 +355,22 @@ func (b *broker) handleReq(pr promisedReq) {
353355
// If we are after the reauth time, try to reauth. We
354356
// can only have an expiry if we went the authenticate
355357
// flow, so we know we are authenticating again.
358+
//
359+
// Some implementations (AWS) occasionally fail for
360+
// unclear reasons (principals change, somehow). If
361+
// we receive SASL_AUTHENTICATION_FAILED, we retry
362+
// once on a new connection. See #249.
363+
//
356364
// For KIP-368.
357365
cxn.cl.cfg.logger.Log(LogLevelDebug, "sasl expiry limit reached, reauthenticating", "broker", logID(cxn.b.meta.NodeID))
358366
if err := cxn.sasl(); err != nil {
359-
pr.promise(nil, err)
360367
cxn.die()
368+
if errors.Is(err, kerr.SaslAuthenticationFailed) && !retriedOnNewConnection {
369+
cxn.cl.cfg.logger.Log(LogLevelDebug, "sasl reauth failed, retrying once on new connection", "broker", logID(cxn.b.meta.NodeID), "err", err)
370+
retriedOnNewConnection = true
371+
goto start
372+
}
373+
pr.promise(nil, err)
361374
return
362375
}
363376
}

0 commit comments

Comments
 (0)
Please sign in to comment.