Repository navigation
MB-74905: Don't lose peer close with {exit_on_close, false} - #36
Conversation
stevewatanabe
left a comment
There was a problem hiding this comment.
A few concerns with this fix. Inline comments cover the main ones; the rest are below.
Possible duplicate close messages. The PassiveTag handler (around L296) calls do_activate_socket whether or not active_n_toggle is set. With transport_closed set, a queued {tcp_passive, S} and the flow_ctrl -> activate_socket path can each send {tcp_closed, S} to self. The first one stops the process, so it's harmless today, but it depends on that ordering.
Two separate ways to redeliver a close. There's now the transport_closed flag and the existing setopts-error branch (around L737). Every activation path has to know about both, and kTLS is one that was missed (see inline). It would be more robust to always record the close at the point it's deferred and stop relying on setopts failing to detect it.
No regression test. Nothing in lib/ssl/test (e.g. ssl_api_SUITE / ssl_socket_SUITE) covers {exit_on_close, false} with a passive socket and a peer FIN. The repro in the PR description would make a good test, and without one a future upstream OTP merge into this branch could silently drop the fix, with ssl:recv hanging until timeout again.
I don't think this sequence can happen. It also doesn't depend on ordering. A redelivered close either stops the connection or is deferred again, and deferring only sets flags that are already set, so a second copy gives the same result whichever is handled first. The two paths can't both fire within one event either: This also isn't new with this change: with
I think the patch already does what you're suggesting. The close is recorded where it's deferred ( Activation paths don't need to know about either mechanism: both are inside I've left the
Added |
If the peer closes the TCP connection while the ssl socket is passive
and nobody is in ssl:recv, the close is deferred until the next socket
activation. The connection relied on the subsequent setopts on the tcp
socket failing in order to re-trigger the close. With
{exit_on_close, false} the tcp port survives the peer close and doesn't
report it again, so setopts succeeds and the close is lost: a later
{active, once} never yields ssl_closed and ssl:recv hangs until
timeout.
Remember the transport close explicitly and deliver it on the next
activation instead of relying on the state of the tcp port.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The peer sends data followed by a TCP FIN without close_notify, which
reaches the connection while the socket is passive and nobody is in
ssl:recv. Check that a later ssl:recv and {active, once} deliver the
data and then report the close, with {exit_on_close, false}. Also check
that data can still be sent to the half-closed peer before that.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0552aac to
6df19d6
Compare
Fixes a lost peer close on TLS sockets using
{exit_on_close, false}.If the peer closes the TCP connection while the ssl socket is passive and no
ssl:recvis pending, ssl defers the close until the next activation and relies onsetoptson the TCP socket failing to rediscover it. With{exit_on_close, false}the TCP port survives the peer close, sosetoptssucceeds and the close is lost:{active, once}never deliversssl_closed, andssl:recvhangs until its timeout.The fix records the transport close explicitly and delivers it on the next activation.
Tested with a standalone repro on OTP 28.5.0.6, TLS 1.2 and 1.3:
exit_on_close=trueexit_on_close=falsessl_closedssl_closed/recvtimeoutssl_closedssl_closed/{error, closed}Data sent before the FIN is still delivered before the close, and
ssl:sendafter the peer's FIN still works.Reported upstream to erlang/otp.
To Reproduce