From 393abd14612e6ac01d0946ef657156ec1941f2fd Mon Sep 17 00:00:00 2001 From: Scott Gress Date: Tue, 8 Apr 2025 15:43:21 -0500 Subject: [PATCH] Ignore EOF errors when sending QUIT to mail server (#27994) For #28000 We started seeing errors in one of our mail tests do to an EOF being received from the mail client when sending the QUIT command. This should be non-fatal (the mail should already have been sent) and it can happen especially in localhost scenarios where things move very fast, and the mail server closes the connection before we have a chance to send QUIT. It's not clear why it started failing consistently when it did; I tried [reverting the commit after the last known good run](https://github.com/fleetdm/fleet/pull/27989) and it had no effect. --- server/mail/mail.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/mail/mail.go b/server/mail/mail.go index 972c6fee30..bb741a43fa 100644 --- a/server/mail/mail.go +++ b/server/mail/mail.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "html/template" + "io" "net" "net/smtp" "strings" @@ -238,7 +239,11 @@ func (m mailService) sendMail(e fleet.Email, msg []byte) error { } if err := client.Quit(); err != nil { - return fmt.Errorf("error on client quit: %w", err) + // Ignore EOF errors on quit, which can happen if the server + // closes the connection after the message is sent. + if !errors.Is(err, io.EOF) { + return fmt.Errorf("error on client quit: %w", err) + } } return nil }