Fix socket leak

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-03-09 11:15:26 +01:00
parent 68d7e4f7a2
commit bf49c825c4

View File

@@ -334,17 +334,16 @@ func (w *SendingWorker) sendMail(ctx context.Context, to []string, msg []byte) e
if err != nil {
return fmt.Errorf("connection error: %w", err)
}
defer func() { _ = conn.Close() }()
if deadline, ok := ctx.Deadline(); ok {
if err := conn.SetDeadline(deadline); err != nil {
_ = conn.Close()
return fmt.Errorf("cannot set connection deadline: %w", err)
}
}
c, err := smtp.NewClient(conn, host)
if err != nil {
_ = conn.Close()
return fmt.Errorf("SMTP client creation error: %w", err)
}
defer func() { _ = c.Quit() }()