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.
This commit is contained in:
Scott Gress 2025-04-08 15:43:21 -05:00 committed by GitHub
parent 31715f8639
commit 393abd1461
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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
}