-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Hello,
WebSocketStream is a great proposal to solve backpressure and cases where sockets are overflown with too many messages. The extension mechanism will also bring needed improvements to WebSockets.
However WebSockets suffer from a huge caveat: currently there is no way to ensure that a message has been sent through the websocket. None. Over a bad network (e.g. hotel wifis), a SINGLE message sent can fail silently with zero means to detect it.
That's a huge problem for reliability, and WebSocketStream are a great opportunity to solve this issue (as nothing else is evolving - See whatwg/html#4727).
This is vital for WebSockets and WebSocketStream: as more and more people find out that WebSockets are unreliable, all the work done around the WebSocketStream may turn useless.
Technical details:
Currently WebSocket.send() stores the message in a buffer and returns immediately.
There is no guarantee that the message will ever be sent.
Even ws.bufferedAmount is not reliable, as it may decrease when the connection is down (messages are passed to the underlying OS, and falsely considered to be sent).
Also, ws.send() throws an error when the WebSocket is in readyState CONNECTING, but fails silently when the WebSocket gets closed, which can easily occur with bad Wifi (high latency and dropped packets).
The only way to guarantee transmission is to implement an acknowledgement protocol on top of websockets, which is silly as it is already implemented at low level!
WebSocket.send() should return a Promise (or have a callback mechanism) that resolves when the message has been successfully sent through the network, and rejects when the message won't be able to be sent (and provides the message that failed).
When searching the internet about this problem, the comments commonly found are "WebSockets are unreliable". It should not be so!
Thank you for helping the Internet become a better medium!