Description
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:
socket.io-client/lib/socket.ts
Lines 387 to 388 in 2edf0f3
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.