fix(smtp-server): treat TLS read disconnects as client-gone, not errors#3604
Open
kiku98 wants to merge 1 commit into
Open
fix(smtp-server): treat TLS read disconnects as client-gone, not errors#3604kiku98 wants to merge 1 commit into
kiku98 wants to merge 1 commit into
Conversation
kiku98
force-pushed
the
fix/smtp-tls-read-eof-noise
branch
from
July 14, 2026 15:58
c6b0141 to
b3e1c2c
Compare
…rors
When a client disconnects abruptly, OpenSSL and the socket layer raise
errors that the SMTP server logged as genuine server errors (with a full
backtrace and Sentry report) despite being routine client-gone events -
commonly caused by port scanners, load-balancer health checks and
senders whose connection drops.
Three paths in the event loop were affected:
- Handshake path: a client resetting the connection mid SSL_accept
raises Errno::ECONNRESET (not an SSLError), which the handshake
rescue did not handle.
- Read path: an abrupt disconnect while reading raises
OpenSSL::SSL::SSLError ("SSL_read: unexpected eof while reading")
rather than an EOFError, which the read rescue did not handle.
- Write path: a client gone before the response is written raises
Errno::EPIPE ("broken pipe") as well as the already-handled
Errno::ECONNRESET.
Extend each rescue so an abrupt disconnect on any path is treated the
same as a plain EOF: the connection is closed quietly instead of being
reported as a server error.
kiku98
force-pushed
the
fix/smtp-tls-read-eof-noise
branch
from
July 14, 2026 16:08
b3e1c2c to
38636f8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a client disconnects abruptly, OpenSSL and the socket layer raise errors that the SMTP server's event loop logged as genuine server errors — with a full backtrace and a Sentry report — despite being routine client-gone events (port scanners, load-balancer health checks, senders whose connection drops).
Three paths in
run_event_loopwere affected, each falling through to the genericrescue StandardError:SSL_acceptraisesErrno::ECONNRESET(not anSSLError), which the handshake rescue did not handle.OpenSSL::SSL::SSLError(SSL_read: unexpected eof while reading) rather than anEOFError. The read rescue only handledEOFError,Errno::ECONNRESETandErrno::ETIMEDOUT, so these fell through.Errno::EPIPE("broken pipe") in addition to the already-handledErrno::ECONNRESET.Fix
Extend each rescue so an abrupt disconnect on any path is treated the same as a plain-socket EOF (
eof = true) — the connection is closed quietly instead of being reported as a server error:Errno::ECONNRESET, Errno::ETIMEDOUTOpenSSL::SSL::SSLErrorErrno::EPIPENo behaviour change for successful connections.