Commit d9bc147
authored
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.1 parent 80f10ce commit d9bc147
1 file changed
+3
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
94 | 97 | | |
95 | 98 | | |
96 | 99 | | |
| |||
0 commit comments