Skip to content

fix(socket.io-client): drop buffered packets for timed-out events - #5645

Open
yxshee wants to merge 1 commit into
socketio:mainfrom
yxshee:fix/drop-timed-out-buffered-packets
Open

yxshee wants to merge 1 commit into
socketio:mainfrom
yxshee:fix/drop-timed-out-buffered-packets

Conversation

@yxshee

@yxshee yxshee commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

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

When a Socket.IO client emits an event with an acknowledgement timeout (socket.timeout(...) or ackTimeout) while connected, the encoded packet(s) are handed to the underlying Engine.IO client and queued in engine.writeBuffer whenever the transport is temporarily unwritable (for example, while an earlier HTTP long-polling write is still in flight on a disrupted network or during a transport upgrade).

If the acknowledgement timer expires before those packets are handed to the transport, Socket#_registerAckCallback() only removes the packet from socket.sendBuffer. The encoded Engine.IO packet(s) remain in engine.writeBuffer and are still flushed to the server once the transport drains.

New behavior

  • Add Socket#_removeFromWriteBuffer(options) in engine.io-client to remove queued packets sharing the same options object reference at indices >= _prevBufferLen (packets not yet handed to the transport).
    • If any packet sharing that options object is already in flight (< _prevBufferLen), all packets sharing it are preserved so multi-packet binary events are never left partially transmitted.
    • If removing buffered packets empties writeBuffer while readyState === "closing", emit "drain" so a pending close() completes cleanly.
  • Add Manager#_removePacketFromBuffer(packet) in socket.io-client delegating to this.engine?._removeFromWriteBuffer?.(packet.options).
  • Update Socket#_registerAckCallback() in socket.io-client so when an acknowledgement times out and the packet is no longer in sendBuffer, it also discards unsent Engine.IO buffered packet(s) for that event before invoking the timeout callback (covering timeout().emit(), emitWithAck(), retries + ackTimeout, binary events, and packets moved from sendBuffer on reconnect).

Other information (e.g. related issues)

Fixes #4318

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.

Timed out event is still buffered

1 participant