Repository navigation
fix(eio-client): use the exact base64 length when merging packets - #5605
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 size of a base64-encoded binary packet was estimated with a factor of 1.33, but the encoded length is 4 * ceil(n / 3). A payload that the client thought fit in maxPayload could be larger, and the server then rejected it with HTTP 413. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
With HTTP long-polling,
_getWritablePackets()keeps the payload under themaxPayloadvalue of the handshake. For a binary packet,byteLength()estimates the size asceil(n * 1.33). But the packet is sent as"b"+ base64, and base64 gives4 * ceil(n / 3)characters, which is more. So a payload that the client thinks fits can be larger thanmaxPayload. The server answers HTTP 413, and the client closes withtransport error.New behavior
byteLength()returns4 * Math.ceil(n / 3)for anArrayBuffer, a typed array or aBlob. The"b"prefix is already counted, as the packet type, in_getWritablePackets(). A payload that is too large is now split into two requests, as for strings.Other information (e.g. related issues)
Fixes #5604
The new test in
test/arraybuffer/polling.js("should use the exact base64 length when merging binary packets") buffers a 1-byte binary packet and a 94-character string before the handshake. The client estimate is 99 bytes, the real payload is 101 bytes, and themaxHttpBufferSizeof the test server is 100.Test results (Node.js 24.21.0, Windows 11, in
packages/engine.io-clientafternpm run compile):mocha --exit --require test/support/hooks.js --require test/support/env.js test/arraybuffer/polling.jslib/: 4 passing, 1 failing: the new test fails withError: unexpected close: transport error(the server answers 413)mocha --exit --require test/support/hooks.js test/index.js(the Node.js suite, withouttest/webtransport.mjs): 99 passing, 1 pending; withUSE_FETCH=1: 98 passing, 2 pendingprettier --checkof the changed files: no problemsThis PR was prepared with AI assistance (Claude). The tests named above were run before and after the change, with the results above.
🤖 Generated with Claude Code