rsocket / rsocket-js

JavaScript implementation of RSocket
https://github.com/rsocket/rsocket-js
Apache License 2.0
594 stars 97 forks source link

Fix: WebSocket Duplex Connection Unhandled Exceptions #278

Open stevensJourney opened 2 months ago

stevensJourney commented 2 months ago

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:

image

Unable to read type of undefined frame: image

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.