einaros/ws — pull request #342 by toejough (2014-08-03 06:38:19+00:00)
Title: Plug WebSocket.terminate timeout leak

If a caller tracks server connections (`WebSocket`s) on their own and cleans them up manually right before calling `WebSocketServer.close`, the calls to `terminate` (one from the caller closing the connection manually, and one from the server loop doing it) can happen so quickly that the internal state is `WebSocket.CLOSING` in both calls.

This means that the second call will over-write the first call's `this._closeTimer`. That means a timer gets leaked, and holds the program open for 30s. Not a huge problem, but a confounding one.

This one-liner will prevent that. The "right" answer is probably to update the state machine, but as far as I can tell, this timeout is the only collateral in this scenario, so the one-liner should be sufficient in practice.