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

Silent NodeJS process termination when missing ws.on('error') handler #2143

Closed
1 task done
dilame opened this issue May 9, 2023 · 5 comments
Closed
1 task done

Comments

@dilame
Copy link

dilame commented May 9, 2023

Is there an existing issue for this?

  • I've searched for any related issues and avoided creating a duplicate issue.

Description

When the error handler for ws.on('error') is not implemented, and an error takes place, the NodeJS process terminates without any warnings or error messages. It took a considerable amount of time and effort to identify the issue, which was eventually discovered after adding the following line of code: ws.on('error', (e) => console.error(e));. Consequently, the error message below was produced:

Error [ERR_SOCKET_CONNECTION_TIMEOUT]: Socket connection timeout
at new NodeError (node:internal/errors:399:5)
at internalConnectMultiple (node:net:1099:20)
at Timeout.internalConnectMultipleTimeout (node:net:1638:3)
at listOnTimeout (node:internal/timers:575:11)
at process.processTimers (node:internal/timers:514:7) {
code: 'ERR_SOCKET_CONNECTION_TIMEOUT'
}

ws version

8.12.0

Node.js Version

v20.1.0

System

System:
OS: macOS 13.3.1
CPU: (10) arm64 Apple M1 Pro
Memory: 98.66 MB / 16.00 GB
Shell: 5.9 - /bin/zsh

Expected result

Unhandled exception throw, or any other indicator what and where gone wrong

Actual result

In the absence of the ws.on('error') handler, the NodeJS process terminates silently without providing any error messages or warnings when an error takes place within the WebSocket connection.

Attachments

No response

@dilame
Copy link
Author

dilame commented May 9, 2023

It seems to be related to nodejs/node#47822 because it doesn't reproduce with NodeJS v18.16.0.

@lpinca
Copy link
Member

lpinca commented May 10, 2023

I can't reproduce.

$ cat index.js 
'use strict';

const WebSocket = require('ws');

const ws = new WebSocket('wss://api.airvisual.com/v2');

$ node -v
v20.1.0
$ node index.js 
node:events:489
      throw er; // Unhandled 'error' event
      ^

Error [ERR_SOCKET_CONNECTION_TIMEOUT]: Socket connection timeout
    at new NodeError (node:internal/errors:399:5)
    at internalConnectMultiple (node:net:1099:20)
    at Timeout.internalConnectMultipleTimeout (node:net:1638:3)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7)
Emitted 'error' event on WebSocket instance at:
    at emitErrorAndClose (/Users/luigi/Desktop/test/node_modules/ws/lib/websocket.js:1008:13)
    at ClientRequest.<anonymous> (/Users/luigi/Desktop/test/node_modules/ws/lib/websocket.js:856:5)
    at ClientRequest.emit (node:events:511:28)
    at TLSSocket.socketErrorListener (node:_http_client:495:9)
    at TLSSocket.emit (node:events:511:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'ERR_SOCKET_CONNECTION_TIMEOUT'
}

Node.js v20.1.0

@dilame
Copy link
Author

dilame commented May 13, 2023

Nvm, my bad, sorry.

@dilame dilame closed this as completed May 13, 2023
@Bubesh21
Copy link

@dilame Would you mind updating how you fixed this? Am facing exactly the same issue.

@dilame
Copy link
Author

dilame commented May 24, 2023

@dilame Would you mind updating how you fixed this? Am facing exactly the same issue.

In short, you just need to downgrade NodeJS version 18. I have not found a way to directly fix it yet

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

3 participants