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

Exception handling in Websocket #6173

Closed
aeolus opened this issue Nov 1, 2019 · 6 comments · Fixed by #6230
Closed

Exception handling in Websocket #6173

aeolus opened this issue Nov 1, 2019 · 6 comments · Fixed by #6230
Labels
type:feature New feature or improvement of existing feature

Comments

@aeolus
Copy link

aeolus commented Nov 1, 2019

Hi, recently in our production environment, we seen exceptions from WebSocket (live query).

The explicit exception is from ws lib:

RangeError: Invalid WebSocket frame: invalid payload length 126

which caused our application to crash because apparently this has been escalated into an uncaughtException for the parse application.

Right now we have no idea about the root cause due to missing logging in the wssocket communication and also don't know the proper fix for it.

By looking at the latest version of parse-server, it seems to be possible to customize the wssocket adapter to explicitly handle errors/incoming traffic etc. However, this adaptor doesn't seem to be available to the public or maybe I just missed something here.

Is there any good suggestion for us to prevent the app from crashing? Thanks

@dplewis
Copy link
Member

dplewis commented Nov 2, 2019

@aeolus You are right there isn't error handling.

Here is the PR for that feature. 218c349#diff-464984cc0483db2f695a4c90c82c0d69

You can pass your wssAdapter into your parse server config. Here is the adapter we use internally.

const server = ParseServer({
  ...otherOptions
  wssAdapter: MyWSSAdapter
});

The question now is what is causing your issue the server or the client?

Edit: What version of node are you running? Maybe updating it will fix your issue.

@aeolus
Copy link
Author

aeolus commented Nov 3, 2019

@dplewis thank you very much for your reply. We are currently running parse-server 3.1.3 and try to move to 3.9.0 (need to update a few places but that's another story).

We run parse-server with Express, it is a little hard since I did not find a good way to troubleshoot websocket server exception or even handle/catch the error itself. With the newer version of parse-server, at least I have the chance to add an on error handler and might just log it instead of rethrowing it to the app.

Base on the current info we have, it is hard to figure out the root cause. It might be related to load (concurrency) on the ws lib, but on the other side, I saw the same problem when the load is not very high. Just googling the error message does not give me much help either. If anybody has a theory, I am all ears.

@dplewis
Copy link
Member

dplewis commented Nov 4, 2019

If you have a web client, you can inspect the web socket connection and view the packets / frames.

Maybe you will find something. That’s all I got, sorry I couldn’t be more helpful

@dplewis dplewis added enhancement type:feature New feature or improvement of existing feature labels Nov 20, 2019
dplewis added a commit that referenced this issue Nov 21, 2019
Closes: #6173

Prevents an unhandled server rejection.

Includes an example for LiveQuery test and closing the proper connections.

Improve live query monitoring
dplewis added a commit that referenced this issue Nov 22, 2019
* Improve WebSocketServer Error Handling

Closes: #6173

Prevents an unhandled server rejection.

Includes an example for LiveQuery test and closing the proper connections.

Improve live query monitoring

* fix tests
@JeffGuKang
Copy link
Contributor

I got the same issue. And dplewis 's PR looks be applied in v3.10.0. Thanks.

@JeffGuKang
Copy link
Contributor

JeffGuKang commented Jan 20, 2020

@dplewis
There is an error even parse server v3.10.0 among running livequery. How can I prevent to terminate node server from the error?

parse-server: 3.10.0

.../node_modules/parse-server/lib/ParseServer.js:229
          throw err;
          ^

RangeError: Invalid WebSocket frame: invalid payload length 126
    at Receiver.getInfo (.../node_modules/parse-server/node_modules/ws/lib/receiver.js:213:16)
    at Receiver.startLoop (.../node_modules/parse-server/node_modules/ws/lib/receiver.js:127:22)
    at Receiver._write (.../node_modules/parse-server/node_modules/ws/lib/receiver.js:74:10)
    at doWrite (_stream_writable.js:415:12)
    at writeOrBuffer (_stream_writable.js:399:5)
    at Receiver.Writable.write (_stream_writable.js:299:11)
    at Socket.socketOnData (.../node_modules/parse-server/node_modules/ws/lib/websocket.js:875:35)
    at Socket.emit (events.js:198:13)
    at Socket.EventEmitter.emit (domain.js:448:20)
    at addChunk (_stream_readable.js:288:12)
[ERROR] 16:23:14 RangeError: Invalid WebSocket frame: invalid payload length 126

@JeffGuKang
Copy link
Contributor

@aeolus Did you got any idea? I have a same issue.

dplewis added a commit that referenced this issue Feb 18, 2020
Closes: #6413, #6173
Prevent crashing on websocket error.

Bonus points to anybody who can post a specific payload that the client sends that returns an error.
davimacedo pushed a commit that referenced this issue Feb 19, 2020
* Websocket: unhandle rejection

Closes: #6413, #6173
Prevent crashing on websocket error.

Bonus points to anybody who can post a specific payload that the client sends that returns an error.

* log the socket

* fix tests

* fix payload reference link
UnderratedDev pushed a commit to UnderratedDev/parse-server that referenced this issue Mar 21, 2020
* Improve WebSocketServer Error Handling

Closes: parse-community#6173

Prevents an unhandled server rejection.

Includes an example for LiveQuery test and closing the proper connections.

Improve live query monitoring

* fix tests
UnderratedDev pushed a commit to UnderratedDev/parse-server that referenced this issue Mar 21, 2020
* Websocket: unhandle rejection

Closes: parse-community#6413, parse-community#6173
Prevent crashing on websocket error.

Bonus points to anybody who can post a specific payload that the client sends that returns an error.

* log the socket

* fix tests

* fix payload reference link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants