Skip to content

fix(eio-client): use the exact base64 length when merging packets - #5605

Open
mark1russell7 wants to merge 1 commit into
socketio:mainfrom
mark1russell7:fix/eio-client-base64-payload-size
Open

mark1russell7 wants to merge 1 commit into
socketio:mainfrom
mark1russell7:fix/eio-client-base64-payload-size

Conversation

@mark1russell7

@mark1russell7 mark1russell7 commented Nov 13, 2026 •

Copy link
Copy Markdown

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behavior

With HTTP long-polling, _getWritablePackets() keeps the payload under the maxPayload value of the handshake. For a binary packet, byteLength() estimates the size as ceil(n * 1.33). But the packet is sent as "b" + base64, and base64 gives 4 * ceil(n / 3) characters, which is more. So a payload that the client thinks fits can be larger than maxPayload. The server answers HTTP 413, and the client closes with transport error.

New behavior

byteLength() returns 4 * Math.ceil(n / 3) for an ArrayBuffer, a typed array or a Blob. 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 the maxHttpBufferSize of the test server is 100.

Test results (Node.js 24.21.0, Windows 11, in packages/engine.io-client after npm run compile):

  • mocha --exit --require test/support/hooks.js --require test/support/env.js test/arraybuffer/polling.js
    • without the change of lib/: 4 passing, 1 failing: the new test fails with Error: unexpected close: transport error (the server answers 413)
    • with the change: 5 passing
  • mocha --exit --require test/support/hooks.js test/index.js (the Node.js suite, without test/webtransport.mjs): 99 passing, 1 pending; with USE_FETCH=1: 98 passing, 2 pending
  • prettier --check of the changed files: no problems

This 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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[engine.io-client] A polling payload with binary packets can exceed maxPayload, and the server rejects it with HTTP 413

1 participant