sprsquish/finagle-libs — pull request #6 by pteichman (2014-10-01 23:01:05+00:00)
Title: Support websocket pings on an idle timeout

We're having issues with dropped websocket connections--easily reproduced by having a mobile client drop off the network (e.g. put it in a microwave for RF insulation and go into airplane mode). In this case, the onClose Future will never fire and cleanup can't occur.

There's some good background here: http://blog.stephencleary.com/2009/05/detection-of-half-open-dropped.html

We've decided to fix this by sending occasional websocket pings when the connection has been idle: they'll fail to send, the connection will be noticed as closed, and everything will shut down properly.

The first patch in this pull request is straightforward: it fills in support for PingWebSocketFrame and PongWebSocketFrame in the client and server handlers. These were caught as invalid messages before.

The second patch is more of a request for direction: it adds the idle timeout (good) with an awful configuration mechanism (`var WebSocket.idlePingTimeout`). This works for me, but it would be far better for this to go through the ServerBuilder or Codec instead of adding mutable state. I haven't figured out how Finagle would expect this to be done.