jenkinsci/websocket-plugin — pull request #2 by jketterl (2012-11-16 13:48:03+00:00)
Title: added keepalive options

hi folks,

my experience with websockets (not only in jenkins but in general) is that it's close to impossible to really tell whether or not the socket is still alive as long as there's no data being sent (this is due to routers, firewalls etc. that are usually timing out idle connections pretty fast).

i was trying to build an xfd out of a toy traffic light (with a raspberry pi inside) and i ran into exactly that problem: the socket would work in the beginning, and the device would display project status correctly as long as the project was active (i.e. people were committing and builds would be made). the next day however, the socket would be dead without the device being aware. the build results the device were displaying were stale.

luckily the designers of the websocket protocol were aware of the basic problem at hand and built a mechanism into the protocol to be able to check for socket availability: pings and pongs.

i took a look at the code of the plugin and did a few changes to hopefully fix that. the most important changes are:

- passive pong messages are now automatically sent out everytime a client sends a ping (this was ignored before, which might lead to unwanted disconnects, depending on the client lib)

- active ping messages are now enabled by default and are sent out to every connected client in 20s intervals. the interval can be configured, or be disabled completely on the jenkins settings page.

this allows both the client and the server to check for socket availability (the corresponding server timeout has not been implemented as of yet).

i am currently testing the modified plugin on our jenkins server, first results are good so far.