Skip to content

Fix event dispatch before disconnection - #5531

Open
mjibulu wants to merge 1 commit into
socketio:mainfrom
mjibulu:fix/5213-disconnect-event-order
Open

mjibulu wants to merge 1 commit into
socketio:mainfrom
mjibulu:fix/5213-disconnect-event-order

Conversation

@mjibulu

@mjibulu mjibulu commented Aug 1, 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

When a complete non-binary event is received before disconnection, onAny() can observe it while the named listener is skipped because dispatch is deferred until after the socket's connection state changes.

New behavior

Complete non-binary events whose middleware completes synchronously are dispatched immediately while the socket is connected. Asynchronous middleware, events received after disconnection, and binary events retain their existing deferred and guarded behavior.

Other information (e.g. related issues)

Fixes #5213

The existing binary-packet regression test associated with #3095 remains unchanged and passes.

@darrachequesne darrachequesne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for your pull request. Please find my review notes below.

this.dispatch(args);
this.dispatch(
args,
packet.type === PacketType.BINARY_EVENT || hasBinary(args),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain the usage of the hasBinary() check here? Both plaintext and binary events should be complete in the ondecoded() handler, no?


this.run(event, (err) => {
process.nextTick(() => {
const invoke = () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we just remove the process.nextTick() call here? Since there is already a nextTick() in the ondecoded handler.

process.nextTick(function () {
socket._onpacket(packet);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Events before disconnection dropped

2 participants