theturtle32 / WebSocket-Node

A WebSocket Implementation for Node.JS (Draft -08 through the final RFC 6455)
Apache License 2.0
3.76k stars 602 forks source link

Close code 1006 is not valid. #254

Closed rosesandhello closed 8 years ago

rosesandhello commented 8 years ago

websocket appears to crash on receiving a close reason code of 1006:

Error: Close code 1006 is not valid. at WebSocketConnection.close (/---/node_modules/websocket/lib/WebSocketConnection.js:422:19) at WebSocketConnection.<anonymous> (/---.js:597:41) at emitTwo (events.js:92:20) at WebSocketConnection.emit (events.js:172:7) at WebSocketConnection.drop (/---/node_modules/websocket/lib/WebSocketConnection.js:468:14) at WebSocketConnection.handleGracePeriodTimer (/---/node_modules/websocket/lib/WebSocketConnection.js:257:10) at Timer.listOnTimeout (timers.js:89:15)

Any insight would be greatly appreciated.

aeisenberg commented 8 years ago

From what I can tell, the close code is not recognized by the websocket spect. From MDN:

1006 CLOSE_ABNORMAL Reserved. Used to indicate that a connection was closed abnormally (that is, with no close frame being sent) when a status code is expected.

That explains why your app is crashing when 1006 is received. I can't explain why your app is receiving it in the first place. It is most likely a bug in the other side.

theturtle32 commented 8 years ago

That's correct. According to the Websocket Spec (RFC 6455, Section 7.4.1):

 1006 is a reserved value and MUST NOT be set as a status code in a
 Close control frame by an endpoint.  It is designated for use in
 applications expecting a status code to indicate that the
 connection was closed abnormally, e.g., without sending or
 receiving a Close control frame.

That error is not thrown when you are receiving a close reason code of 1006, but rather when you are trying to send a close reason code of 1006, which is not allowed. Line 422 of WebSocketConnection.js is inside the close method, which is invoked by your code, not as part of handling a close frame from the remote peer.