Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client-ws-transport): Flush send queue in close() to avoid race (#…
…9101) Before this there were a race between `setTimeout` in `sendMessage` and `close`. Even for a good citizen, that calls `unsubscribe` and awaits result there were no synchronization between `unsubscribe` adding message to `messageQueue` and restarting timer, and actually sending this message to WebSocket. When `close()` is called close frame is sent immediately to WebSocket. If at that moment `messageQueue` is not empty, and timer is armed, it can wake up, and discover socket in CLOSING state: send side closed, recv side open. For now - just flush everything queued, and send close frame after, so it would look like close was queued after. More complete solution is to add synchronization between unsubscribe call and sending message, or even receiving ack for it.
- Loading branch information