rsocket-js
rsocket-js copied to clipboard
Fix: WebSocket Duplex Connection Unhandled Exceptions
This fixes some potential unhandled exceptions in rsocket-websocket-server
relating to the underlying WebSocket readyState
and deserialisation of invalid frames.
Motivation:
I've noticed intermittent unhandled exceptions for the errors below:
WebSocket is in CLOSING state:
Unable to read type
of undefined frame:
Modifications:
WebSocket readyState
The WebSocket from the ws
library is now used to check the readyState
before calling write
on the Duplex stream.
Undefined frame:
I believe this error was caused by the deserializeFrame
method returning undefined. This could be verified by a client connecting to the server WebSocket port and sending a random Buffer payload.
The connection will now close if no valid frame could be deserialised.
Result:
The external API and behaviour should be the same as before. There should now be less potential for unhandled exceptions.
Side Note:
I've noticed some formatting changes were included here. Is there perhaps a Prettier config I could use? Running yarn lint
on my machine also shows errors for other package's files. Perhaps this is somehow linking to external settings I might have. Please advise.