make ExtendAuthSession JWT-retry backoff cancellable

Skip the retry log and 200ms wait on the final attempt, and replace the
uncancellable time.Sleep with a select on time.After/ctx.Done so an
upstream cancellation aborts the wait instead of running it to
completion.
This commit is contained in:
Zoltán Papp
2026-05-19 17:35:56 +02:00
parent cfeb15fe2a
commit 48b1ab010e

View File

@@ -845,13 +845,21 @@ func (s *Server) ExtendAuthSession(ctx context.Context, req *proto.EncryptedMess
}
var userID string
for i := 0; i < 3; i++ {
const attempts = 3
for i := 0; i < attempts; i++ {
userID, err = s.validateToken(ctx, peerKey.String(), jwt)
if err == nil {
break
}
if i == attempts-1 {
break
}
log.WithContext(ctx).Warnf("failed validating JWT token while extending session for peer %s: %v. Retrying (idP cache).", peerKey.String(), err)
time.Sleep(200 * time.Millisecond)
select {
case <-time.After(200 * time.Millisecond):
case <-ctx.Done():
return nil, ctx.Err()
}
}
if err != nil {
return nil, err