mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 17:04:39 +03:00
check and log errors more often in deferred cleanup calls, and log remote-induced errors at lower priority
We normally check errors for all operations. But for some cleanup calls, eg "defer file.Close()", we didn't. Now we also check and log most of those. Partially because those errors can point to some mishandling or unexpected code paths (eg file unexpected already closed). And in part to make it easier to use "errcheck" to find the real missing error checks, there is too much noise now. The log.Check function can now be used unconditionally for checking and logging about errors. It adjusts the log level if the error is caused by a network connection being closed, or a context is canceled or its deadline reached, or a socket deadline is reached.
This commit is contained in:
@ -398,7 +398,7 @@ type recipient struct {
|
||||
}
|
||||
|
||||
func isClosed(err error) bool {
|
||||
return errors.Is(err, errIO) || moxio.IsClosed(err)
|
||||
return errors.Is(err, errIO) || mlog.IsClosed(err)
|
||||
}
|
||||
|
||||
// Logbg returns a logger for logging in the background (in a goroutine), eg for
|
||||
@ -934,8 +934,9 @@ func serve(listenerName string, cid int64, hostname dns.Domain, tlsConfig *tls.C
|
||||
slog.String("listener", listenerName))
|
||||
|
||||
defer func() {
|
||||
c.origConn.Close() // Close actual TCP socket, regardless of TLS on top.
|
||||
c.conn.Close() // If TLS, will try to write alert notification to already closed socket, returning error quickly.
|
||||
err := c.origConn.Close() // Close actual TCP socket, regardless of TLS on top.
|
||||
c.log.Check(err, "closing tcp connection")
|
||||
c.conn.Close() // If TLS, will try to write alert notification to already closed socket, returning error quickly.
|
||||
|
||||
if c.account != nil {
|
||||
err := c.account.Close()
|
||||
|
Reference in New Issue
Block a user