substack/bouncy — pull request #27 by sethml (2012-03-12 20:36:06+00:00)
Title: Handle socket errors, add onConnectionError opt.

When not handling errors on the socket connection, long-lived requests (for example WebSocket connections) which eventually have a TCP timeout (for example, if the client has its network cable disconnected) will eventually cause an unhandled socket error which kills bouncy.

This change handles those errors. It also allows setting an option onConnectionError so that the code invoking bouncy can print a message when a connection error occurs. In order to do this, I stick the callback into opts and pass opts to the handler, which as a side-effect lets you pass the callback as an option, which I think is cleaner.

If you hate this approach, I can revert the opts.onConnectionError part of this change. Installing an error handler on the socket is pretty critical, though - otherwise we were seeing frequent bouncer death when using websockets.