Skip to content

sendBuffer should be emptied before emit #1458

Closed
@dwelle

Description

@dwelle

Describe the bug

Right now it's possible to emit a message before sendBuffer is emptied after reconnection. This will result in out-of-order messages arriving on the server.

To Reproduce

Upon disconnect, emit a message A, and upon connect, emit a message B. The messages will be sent in this order: B, A.

Consider a case where A is a roomLeave message and B is a roomJoin message, in which case the order is significant.

This is because the onconnect handler notifies event subscribers before emptying the buffer:

this.emitReserved("connect");
this.emitBuffered();

While currently this seems to be the only code path in which this behavior manifests, it may also affect other code paths in the future so I think the problem generalizes to this issue's title.

Socket.IO client version: 4.x.x

Expected behavior

emit() should check if sendBuffer contains messages and send those beforehand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions