What happens to the queued packets when socket is reconnected? Is there even a queue for packets? #3971
-
I'm asking for socket.io-client. As you can see here and here, when a packet needs to be sent, the packet is encoded and sent directly with Engine.IO socket. Is there a queue for packets in case packet never gets sent? What happens when a packet send fails? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
If the socket is not connected, the packet is buffered: https://github.com/socketio/socket.io-client/blob/b466c6f0b1dd5ef1a2149abc89d1884d376c0eee/lib/socket.ts#L190 If it is connected but fails to be sent at the Engine.IO level, it seems the packet is simply discarded/lost, as the |
Beta Was this translation helpful? Give feedback.
-
The send function of the browser WebSocket doesn't have a mechanism for error reporting. It could have given an exception or call a callback function on success. I think this is the only obstacle. JavaScript sucks. For example you can check for an error with Go: But with the browser JavaScript WebSocket class, you can't. |
Beta Was this translation helpful? Give feedback.
If the socket is not connected, the packet is buffered: https://github.com/socketio/socket.io-client/blob/b466c6f0b1dd5ef1a2149abc89d1884d376c0eee/lib/socket.ts#L190
If it is connected but fails to be sent at the Engine.IO level, it seems the packet is simply discarded/lost, as the
writeBuffer
here is not used when receiving aclose
event. Which is a bit surprising actually, we could maybe try to send it upon reconnection. What do you think?