From c67955ef0d5615d493f69bba3fd23f46d27a8d0a Mon Sep 17 00:00:00 2001 From: Martin Matous Date: Thu, 24 Aug 2023 18:17:08 +0200 Subject: [PATCH] fix(session): detect canceled lookup correctly cancelation is not DNSError, so UnwrapDNSErr() returns "" as reason Signed-off-by: Martin Matous --- internal/endpoint/smtp/session.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/endpoint/smtp/session.go b/internal/endpoint/smtp/session.go index dfa19ea0..6f2c68e5 100644 --- a/internal/endpoint/smtp/session.go +++ b/internal/endpoint/smtp/session.go @@ -319,13 +319,13 @@ func (s *Session) fetchRDNSName(ctx context.Context) { return } - reason, misc := exterrors.UnwrapDNSErr(err) - misc["reason"] = reason - if !strings.HasSuffix(reason, "canceled") { + if !errors.Is(err, context.Canceled) { // Often occurs when transaction completes before rDNS lookup and // rDNS name was not actually needed. So do not log cancelation // error if that's the case. + reason, misc := exterrors.UnwrapDNSErr(err) + misc["reason"] = reason s.log.Error("rDNS error", exterrors.WithFields(err, misc), "src_ip", s.connState.RemoteAddr) } s.connState.RDNSName.Set(nil, err)