From 2f5e3023c2cc51d79aadd3c80ae2c79dda2d798b Mon Sep 17 00:00:00 2001 From: Karl Persson Date: Tue, 26 Mar 2024 11:36:44 +0100 Subject: [PATCH] IDFowrarding: ignore logging context canceled errors (#85141) --- pkg/services/auth/idimpl/service.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/services/auth/idimpl/service.go b/pkg/services/auth/idimpl/service.go index 07c5cc5991d..48eac95a955 100644 --- a/pkg/services/auth/idimpl/service.go +++ b/pkg/services/auth/idimpl/service.go @@ -159,8 +159,10 @@ func (s *Service) hook(ctx context.Context, identity *authn.Identity, _ *authn.R // FIXME(kalleep): we should probably lazy load this token, err := s.SignIdentity(ctx, identity) if err != nil { - namespace, id := identity.GetNamespacedID() - s.logger.FromContext(ctx).Error("Failed to sign id token", "err", err, "namespace", namespace, "id", id) + if shouldLogErr(err) { + namespace, id := identity.GetNamespacedID() + s.logger.FromContext(ctx).Error("Failed to sign id token", "err", err, "namespace", namespace, "id", id) + } // for now don't return error so we don't break authentication from this hook return nil } @@ -180,3 +182,7 @@ func getSubject(namespace, identifier string) string { func prefixCacheKey(key string) string { return fmt.Sprintf("%s-%s", cachePrefix, key) } + +func shouldLogErr(err error) bool { + return !errors.Is(err, context.Canceled) +}