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
Uncaught, unspecified "error" event. #246
Comments
I'm getting same error when using certain browsers, huh! |
And what "certain" browsers are talking about? Does this mean you have a reproducible test case? |
opera 12.16 |
it happens every time with opera, not sure why |
What are you guys sendings over the WebSocket connection? are they small chunks of data, rapid chunks, large chunks of data, binary? Any insight would be welcome. |
well, i am sending raw pcm audio chunks (binary data), chunks are not too big (up to 100kb) at 1 second interval |
but it crashes before sending starts, will try to debug it tonight and will give you more details about what's happening |
@ktor9 I think i've discovered at least one small race condition in this; I've committed a potential fix it here: https://github.com/einaros/ws/tree/error-before-close What i've been seeing is that the So emitting the Btw, what platform are you running on? Linux, Windows, Mac OSX? |
Same error here with Safari 5.0.5 on MacOS. As far as I can tell it happens during the connection or shortly after (within seconds). Using your branch does not fix the error but I do get a longer stacktrace:
|
Hello, I'm also experiencing this problem. It is not easy to reproduce but I know it happened shortly after the connection was established as the client sends a message onopen and this message was not received. The log follows but unfortunately I don't think it adds much 😫
|
Any update or workaround on this? |
This takes advantage of websockets/ws#246
@jeremyBanks that's because you're missing error listeners? So ofcourse it's going to throw if you don't have any listeners assigned. it's how node works, no error listener? error? it will throw. |
@3rd-Eden Please ignore my newbish stupidity. Thanks for the clarification. |
@3rd-Eden Please mind my noobish question but I didn't get where should one attach the error listener. The below code still throws the error: var socketServer = new (require('ws').Server)({port: WEBSOCKET_PORT}); socketServer.on('connection', function(socket) { socket.on('error', function(err){ console.log(err) }); ... }); |
I am getting this error (or a similar error) as well.
|
Information and solution This error still happens on the latest version as of today (2014/11/1). Stack trace:
Reason: if (data[0] !== 0x00) {
self.error('payload must start with 0x00 byte', true);
return;
} However, it happens when creating the connection, before the 'connection' fired.
( Source: http://nodejs.org/api/events.html#events_class_events_eventemitter ) However, because we don't have any access to the new Websocket instance before connection initialized to attach the error listener. I had to modify the library's code itself to fix it !!!! Solution (Hack): node_modules/ws//lib/WebSocket.js:55 function WebSocket(address, protocols, options) {
if (protocols && !Array.isArray(protocols) && 'object' == typeof protocols) {
// accept the "options" Object as the 2nd argument
options = protocols;
protocols = null;
}
if ('string' == typeof protocols) {
protocols = [ protocols ];
}
if (!Array.isArray(protocols)) {
protocols = [];
}
// TODO: actually handle the `Sub-Protocols` part of the WebSocket client
this._socket = null;
this.bytesReceived = 0;
this.readyState = null;
this.supports = {};
// ######### Added by DN at 2014/11/1: to fix a crash if error event happens before 'connection' event fired, we didn't have any chance to set error handler yet
this.on('error', function(a,b) {console.error('[WebSocket Error!]',a,b)})
// ######### Add End ######
if (Array.isArray(address)) {
initAsServerClient.apply(this, address.concat(options));
} else {
initAsClient.apply(this, [address, protocols, options]);
}
} Reproduce: |
@Dragonight Great! |
Continue - After rolling out my fix in production, my logs showed a few more errors, not only the one that I wrote about above. So you need to fix the general case, not the specific case that I wrote about.
I don't know which client is sending the bad data. It started to happen only after I added wss (https) option, so I guess maybe that's have something with wss (websocket secure) that is generating invalid data on a very specific configuration of 1 user (all of other users don't have any problems). So let's assume that an evil person writes a simple script that is sending the right invalid data on purpose to make you crash! - So he can crash any nodejs server that runs "ws" for websockets !!! This bug reported 1 year ago, so I guess all current production servers who use "ws" are vulnerable. Thanks,
|
I'm getting this with a custom client I was writing
I get a reply from the server, then I close the connection. This error occurs before the connection is closed, after the reply.
|
My quick'n'dirty hack. Use at your own risk.
|
@Dragonight Thx very much for your hack 👍 it's working fine for me. |
thanks, any reason its not got fixed? |
My API using ws started crashing every day or so, I put in a listener, and see that it's this error ("reserved fields must be empty 1002"). I am connecting to it with IPWorks ws client and we're only sending basic json strings, any ideas? |
I get "Uncaught, unspecified "error" event. (reserved fields must be empty)" when I write raw json object to the socket after connection has established let socket = net.connect({
port: 2001,
host: '127.0.0.1'
}, function () {
console.log('connected');
socket.write([
'GET / HTTP/1.1',
'Host: localhost',
'Upgrade: websocket',
'Origin: partner',
'Connection: Upgrade',
'Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==',
'Sec-WebSocket-Protocol: splyt-protocol',
'Sec-WebSocket-Version: 13',
'', ''
].join('\n'));
setTimeout(function () {
socket.write(JSON.stringify({}));
}, 200);
}); that fixes the problem. webSocketServer.on('connection', function (socket) {
socket.on('error', function (err) {
//handle or ignore the error
});
}); |
Handling the |
Fixed issue websockets/ws#246. The occurred error with reason "invalid error code" crashes program execution. This patch helps to fix this problem.
@rainder, thanks your fix works for me. |
I received this error:
Node-ws-server seems to run for up to 1 to 48 hours, then I receive that error stated above. I am not sure what is happend. Or if the the packet being sent over web-socket is corrupt or some thing else. What should I do to fix this error?
websocket code:
The text was updated successfully, but these errors were encountered: