fix: report the close frame as the disconnect reason - #92
Merged
Conversation
nmbrone
force-pushed
the
fix/close-reason
branch
from
September 3, 2026 17:21
4f00b0f to
16304a0
Compare
nmbrone
force-pushed
the
fix/close-reason
branch
6 times, most recently
from
September 3, 2026 17:48
06f3a93 to
62b679d
Compare
nmbrone
force-pushed
the
fix/close-reason
branch
4 times, most recently
from
September 4, 2026 07:53
8f1d8f8 to
6bbd442
Compare
vshev4enko
approved these changes
Sep 4, 2026
nmbrone
force-pushed
the
fix/close-reason
branch
from
September 4, 2026 08:17
6bbd442 to
971083f
Compare
The close handshake is handled internally, so the code and reason the server
sent were dropped: `handle_disconnect/3` only ever saw the transport error from
the socket shutting down afterwards, leaving application close codes such as
1008 or the 4000 range unreachable.
Remember the frame when the handshake starts and report it instead, falling
back to the Mint error when there was no handshake. The frame is cleared on
close so a code cannot leak into the next connection's disconnect.
`handle_disconnect/3` now receives `{:close, code, reason}` where it previously
received `%Mint.TransportError{reason: :closed}` for a connection closed through
the handshake by either side.
fix: cancel the previous close timer when starting a handshake
`send_close/2` overwrote `close_timer` without cancelling it, and `close/1` only
cancels the timer it can see. Two handshakes inside the timeout window left the
first timer armed, so it fired after the connection had been closed and
re-established, and tore down the healthy connection.
feat: add the `:close_timeout` option
How long to wait for the server to close the connection once a close handshake
has started, in milliseconds, defaulting to the 5000 that used to be hardcoded.
Also makes the timeout testable: the new test suspends the server so the
handshake is never answered.
nmbrone
force-pushed
the
fix/close-reason
branch
from
September 4, 2026 08:39
971083f to
8ab7c14
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.
The close handshake is handled internally, so the code and reason the server sent never reached the client —
handle_disconnect/3only saw the transport error from the socket closing afterwards, which made application close codes unreachable.It now reports the close frame instead, whichever side started the handshake. Also cancels a previous close timer when a new handshake starts, and adds a
:close_timeoutoption (default5000).handle_disconnect/3receives{:close, code, reason}where it previously received%Mint.TransportError{reason: :closed}.