Repository navigation
Conversation
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
In
engine.io-client,Polling#onData()explicitly handles incoming Engine.IO"close"packets ("1") by closing the transport with{ description: "transport closed by the server" }instead of forwarding them as"packet"events. In contrast,WebSocket(viaTransport#onData()->Transport#onPacket()) andWebTransport(viaTransport#onPacket()) forward"close"packets up toSocket#_onPacket(), which has no"close"case, leaving the transport and underlying connection open.New behavior
Transport#onPacket()now handlespacket.type === "close"by closing the underlying transport viathis.doClose()and invokingthis.onClose({ description: "transport closed by the server" })whenthis.readyState !== "closed", matchingPolling's close details without emitting a"packet"event. (Polling#onData()continues to intercept"close"packets directly so it does not triggerPolling#doClose(), which writes a close packet back to the server.)BaseWS#doClose()guardsif (this.ws)and clearsonopen,onclose,onmessage, andonerrorhandlers before callingthis.ws.close(), preventing the WebSocket's asynchronousonclosecallback from invokingonClose()a second time.WTguards its_transport.closedhandlers and read loop withthis.readyState !== "closed"so WebTransport stops reading and does not invokeonClose()a second time after closing on a"close"packet.Other information (e.g. related issues)
Fixes #5286.
Added regression tests in
packages/engine.io-client/test/node.js(covering server-sent"close"packets over WebSocket, Polling, and upgraded Polling -> WebSocket acrossws,fetch, and built-inWebSocket) andpackages/engine.io-client/test/webtransport.mjs(covering WebTransport), asserting close reason/details, closed states, no"close"packet emission, closure of the underlying server connection, and singletransport.onClose()invocation.