-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Ping() hard crashes Node.js #1952
Comments
Sounds like a Node.js bug. Are you able to get a core dump? |
Also note that ws always write buffers so that stack trace is a bit surprising. |
Found it! This is what happens if you set Repro: const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
wss.on('connection', function connection(ws) {
ws.ping();
ws.on('pong', () => console.log('got pong'));
});
const ws = new WebSocket(`ws://localhost:8080`, { objectMode: true }); // <--
ws.on('ping', () => console.log('got ping')); With object mode set you get an immediate crash & node native stack trace. Without object mode you get:
This happened because I'm using websocket-stream to wrap WS as a node stream, since my WS client code needs to work in both browsers & node (while WS's createWebSocketStream is Node-only). I wanted object mode elsewhere in my pipeline, it snuck into the websocket-stream setup, and that option was then passed through to WS and broke everything. I'll close for this now, since it's clearly my bug and it's now fixed. It's an easy mistake to make though and hard to catch (since most other methods seem to all keep working just fine, if you don't actually write objects) so it might be nice to protect against this in WS. It would be easy to enforce |
Keep in mind that |
I think this should be addressed in Node.js core.
|
Description
I'm testing keep alives in my WS application. I've just tried setting them to be sent all the time every 100ms, just for testing, and node.js core dumps when
ping()
is called.The relevant code looks like this:
If I comment out the
ping()
line, everything works fine. There might be another underlying cause elsewhere, but it's definitely the ping that triggers this. The server and client are both running on localhost in the same node.js process (as part of my test suite) and they're both using ws.This is triggered immediately, so it's possible that I'm pinging during connection setup, after teardown or some other edge case. Regardless though, this shouldn't happen.
It's difficult to isolate this further down to a minimal reproduction, but if I do manage to do so I'll share that here.
ws version
Tested on both 8.2.2 & 7.55
Node.js Version
Tested on 14.17.0 and 16.8.0
System
Expected result
client.ping()
should either work, or raise a handleable error somewhere. It should never crash node.Actual result
(from v16.8.0)
Attachments
No response
The text was updated successfully, but these errors were encountered: