Repository navigation
fix(sio-client): remove the ack handler of a discarded volatile packet - #5622
Open
mark1russell7 wants to merge 1 commit into
Open
mark1russell7 wants to merge 1 commit into
mark1russell7 wants to merge 1 commit into
Conversation
The ack handler was registered before the volatile packet was discarded, and it was never removed: the handler leaked, and emitWithAck() never settled. Now the handler is removed once the packet is discarded. As in _clearAcks(), a handler that accepts an error as first argument (with a timeout, or emitWithAck()) is called with an error.
1 of 5 tasks
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
emit()registers the ack handler before it decides to discard a volatile packet, and nothing removes the handler when the packet is discarded. The server never acknowledges the packet, so the handler stays insocket.acks,emitWithAck()never settles, and the callback oftimeout()gets an error only when the timer ends.New behavior
The client removes the handler when it discards the packet. As in
_clearAcks(), a handler that takes an error as first argument (withtimeout(), oremitWithAck()) is called at once with an error ("packet has been discarded").Three tests are added in
test/socket.ts: a callback, a callback withtimeout(), andemitWithAck().The tests ran in GitHub Actions (Node.js 24.22.2 on Linux): the new tests with the
libfolder of upstream main (before), then with this change (after), thennpm testof socket.io-client with this change:The failures before the change:
Other information (e.g. related issues)
Closes #5615
This PR and #5621 add tests at the same place in
test/socket.ts. When one is merged, I will update the other.This PR was prepared with AI assistance (Claude). The tests above were run before and after the change, with the results above.
🤖 Generated with Claude Code