Repository navigation
fix(sio-client): disconnect on the server side when disconnect() is called during the handshake - #5632
Open
vladosskins178 wants to merge 1 commit into
Open
fix(sio-client): disconnect on the server side when disconnect() is called during the handshake#5632vladosskins178 wants to merge 1 commit into
vladosskins178 wants to merge 1 commit into
Conversation
…alled during the handshake When disconnect() was called after the CONNECT packet was sent but before the server answered, nothing was sent to the server, and the reply was ignored since the socket was no longer active. The server then kept a socket that the client had closed. The DISCONNECT packet cannot be sent right away (the server has no socket for the namespace yet and would close the whole connection), so it is now sent once the server has answered the CONNECT packet. Calling connect() again before that answer waits for it instead of sending a second CONNECT packet. Related: socketio#5617
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 kind of change this PR does introduce
Current behavior
If
disconnect()is called after the client sent the CONNECT packet of a namespace, but before the server answered, the client sends nothing.destroy()removes the packet listener, so the CONNECT reply is ignored. The server completes the handshake and keeps that socket (rooms, handlers) until the whole connection closes (#5617).New behavior
This implements the approach suggested in the issue. The DISCONNECT packet can't be sent right away, because the server has no socket for the namespace yet and would close the whole connection. So when
disconnect()is called during the handshake, the socket adds a one-off listener on the Manager:If
connect()is called again before the reply arrives, the listener is removed. The socket then waits for the reply to the CONNECT packet it already sent, instead of sending a second one. Today that case sends a second CONNECT: the server creates two sockets andconnectfires twice.If the socket was the only one, the Manager closes the connection as before (nothing changes there).
Tests (in
test/socket.ts, with a/slow-handshakenamespace whose middleware answers after 100 ms):connectfires 2 times), passes with this change.Run locally (Node.js 24.14, Linux):
test:node: 118 passing.format:checkandcompilepass.test/index.ts, which uses this client: 219 passing.server /foo socketsgoes from 1 to 0, and the root namespace stays connected.Both suites were rerun from a fresh clone of the branch with the same results. I didn't run the browser tests.
Other information (e.g. related issues)
Closes #5617
Related: #5623 (open) stops
connect()from sending a second CONNECT while the socket is still active. This PR coversdisconnect()during the handshake, anddisconnect()followed byconnect(), where the socket is no longer active. They touchconnect()in different branches.