Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] WebSocket Close Bugs #11

Merged
merged 9 commits into from
Jun 11, 2024
Merged

[Fix] WebSocket Close Bugs #11

merged 9 commits into from
Jun 11, 2024

Conversation

stevensJourney
Copy link
Collaborator

@stevensJourney stevensJourney commented Jun 10, 2024

Overview

Recent alerts have shown uncaught exceptions for clients using the WebSockets connection method. Two main issues were identified.

Write to closed WebSocket

In some circumstances the WebSocket might close unexpectedly. If the server tried to write data to this port an unhandled exception would be thrown.

WebSocket is not open: readyState 2 (CLOSING)

An investigation led to this issue websockets/ws#1515.

This PR adds better error and closed socket handling to the WebSocketDuplexConnection and WebSocketServerTransport implementations provided by RSocket.

A unit test has been added to ensure no unhandled exceptions are thrown when the client closes the WebSocket.

Undefined frames

Some reports of the server failing to handle WebSocket frames were received.

image

This was reproducible by sending invalid data (not a valid RSocket frame buffer) over a WebSocket. Although not verified: this might be caused by a broken Buffer implementation on the client side which could happen in environments such as React Native.

Additional guards have been added to the WebSocketDuplexConnection frame handling. Unit tests have also been added for invalid frames.

Double close warning

Previously a double close warning for the RSocket server could be seen in logs. Currently we use a Fastify server which a WebSocket server manages upgrade events on. The standard RSocket WebSocketServerTransport registers a listener for the close event of the WebSocketServer and calls the ServerCloseable close wherein the server is again closed. This behaviour has been removed as the WebSocket server's closing is tied to the Fastify server's close event.

Additional Fixes

This PR includes some additional bug fixes:

  • Included TypeScript path references for the server project.
  • Added authentication errors to WebSocket responses
  • Added git ignored .probes folder for service folder

@stevensJourney stevensJourney marked this pull request as ready for review June 10, 2024 15:36
@rkistner
Copy link
Contributor

Is it feasible to also get the changes upstream in rsocket-websocket-server, or will we have to continue maintaining forked code?

@stevensJourney
Copy link
Collaborator Author

stevensJourney commented Jun 10, 2024

Is it feasible to also get the changes upstream in rsocket-websocket-server, or will we have to continue maintaining forked code?

I can make a PR on their repository with these changes. I think making the changes here would be the fastest solution in the interim.

Update: I have submitted two PRs for these fixes upstream. rsocket/rsocket-js#278 and rsocket/rsocket-js#279

@stevensJourney stevensJourney merged commit b5f4ebf into main Jun 11, 2024
8 checks passed
@stevensJourney stevensJourney deleted the fix/close-errors branch June 11, 2024 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants