TBEDP/agentkeepalive — pull request #1 by willwhite (2012-09-19 18:49:41+00:00)
Title: Fix duplicate calls to timeout callbacks

This pull adds a workaround for something that appears to be a bug in node's handling of timeout callback (something that is being addressed there in the ongoing rewrite of the http module).

I notice that timeout callbacks stack up on the socket and that callbacks set from previous requests are fired when a subsequent request times out. There are two big problems with this. If you are running many request and none of them timeout, you run the risk of memory problems with a growing list of stale timeout callbacks. If a request does happen to timeout, you old code will be executed many times.

This hasn't cropped up in our usage until we started looking at this project because sockets are very short lived in node core, but since sockets are more persistent with this project there is a great chance that the callbacks will stack up.

This pull addresses the issue by clearing all listener to the `timeout` event from the socket. Since we use the `timeout` event to mange the `maxKeepAliveTime`, we must reset our callback.