josephg/node-browserchannel

Uncaught error on hangup (new in nodejs v0.8.20)

Closed this issue · 5 comments

dejj commented

nodejs Node v0.8.20 (Stable) introduced the following change:

http: Raise hangup error on destroyed socket write (isaacs)

This breaks server.coffee on line 910 with the following error:

timers.js:103
            if (!process.listeners('uncaughtException').length) throw e;
                                                                      ^
Error: socket hang up
    at createHangUpError (http.js:1360:15)
    at ServerResponse.OutgoingMessage._writeRaw (http.js:507:26)
    at ServerResponse.OutgoingMessage._send (http.js:476:15)
    at ServerResponse.OutgoingMessage.write (http.js:740:18)
    at messagingMethods.writeRaw (/home/dejj/myproject/node_modules/browserchannel/lib/server.coffee:93:22)
    at Object.module.exports.session [as _onTimeout] (/home/dejj/myproject/node_modules/browserchannel/lib/server.coffee:557:13)
    at Timer.list.ontimeout (timers.js:101:19)

Setting the timeout needs to be wrapped in try-catch and possibly some error handling.

Also see: socketio/socket.io#1160

+1. This breaks our app when we tried to upgrade to 0.8.20.

Yep, that sure would crash browserchannel. Closed sockets throwing errors is annoying - though I can't complain too much since browserchannel has the same behaviour :)

The simplest fix is to make the write methods ( eg these: https://github.com/josephg/node-browserchannel/blob/master/lib/server.coffee#L180-L181 ) do nothing if the socket is already closed.

This actually seems to be resolved by simply upgrading to node v0.8.21

Yeah, this issue is isolated to 0.8.20. Just don't use that version of nodejs.