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

Unhandled errors in subscriptions crashes server. #430

Open
SkeLLLa opened this issue Mar 27, 2021 · 2 comments
Open

Unhandled errors in subscriptions crashes server. #430

SkeLLLa opened this issue Mar 27, 2021 · 2 comments

Comments

@SkeLLLa
Copy link
Contributor

SkeLLLa commented Mar 27, 2021

I've recently had some errors in logs after which the whole server got crashed.

Here's an example:

events.js:292
      throw er; // Unhandled 'error' event
      ^
RangeError: Invalid WebSocket frame: invalid status code 21021
    at Receiver.controlMessage (/opt/service/node_modules/ws/lib/receiver.js:464:18)
    at Receiver.getData (/opt/service/node_modules/ws/lib/receiver.js:350:42)
    at Receiver.startLoop (/opt/service/node_modules/ws/lib/receiver.js:143:22)
    at Receiver._write (/opt/service/node_modules/ws/lib/receiver.js:78:10)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at Receiver.Writable.write (internal/streams/writable.js:303:10)
    at Socket.socketOnData (/opt/service/node_modules/ws/lib/websocket.js:900:35)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
Emitted 'error' event on Duplex instance at:
    at Duplex.duplexOnError (/opt/service/node_modules/ws/lib/stream.js:37:10)
    at Duplex.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  [Symbol(status-code)]: 1002
}

Is there any way to add custom error handler to it, to log more details?

@mcollina
Copy link
Collaborator

Looks like a bug somewhere between mercurius and fastify-websocket.

You can get the websocket via https://github.com/websockets/ws/blob/HEAD/doc/ws.md#event-connection, you should have the websocket server exposed via https://github.com/fastify/fastify-websocket/blob/c99252b99d2ed23ca804d85a75805f8c3e199d96/index.js#L37. If you register fastify-websocket before mercurius, your instance will be used instead. Look at

// If `fastify.websocketServer` exists, it means `fastify-websocket` already registered.
// Without this check, fastify-websocket will be registered multiple times and raises FST_ERR_DEC_ALREADY_PRESENT.
if (fastify.websocketServer === undefined) {
fastify.register(fastifyWebsocket, {
options: {
maxPayload: 1048576,
verifyClient
}
})
}
for more details.

Can you write a small repro?

@SkeLLLa
Copy link
Contributor Author

SkeLLLa commented Mar 28, 2021

Yes, I'll try to create a reproduction. So far I can tell that bug might be connected to create react app built-in proxy, because before such errors like

"path":"/sockjs-node","msg":"closed incoming websocket connection for path with no websocket handler"

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

No branches or pull requests

2 participants