Looks like I can do something like this:
function onTimeout(){
req.abort();
}
function clearTimeout(req){
req.socket.removeListener('timeout', onTimeout);
}
req.setTimeout(timeout, onTimeout);
And then call clearTimeout in res.on('end') and req.on('error') callbacks.
It seems a bit out of place since it relies on implementation details for
clientRequest and socket to figure it out, whereas req.setTimeout abstracts
those details away.
On Thursday, April 5, 2012 1:50:40 PM UTC-4, Paul Selden wrote:
>
> Sorry, I should be more clear -- what do I actually unbind? Do I have to
> get at the actual EventEmitter through the socket? Will setTimeout(0)
> remove the previous listeners (documentation just states that it disables,
> doesn't explicitly say remove).
>
> This sort of seems like functionality that might fit into core for
> req.setTimeout (removing the listener after the request finishes).
>
> Thanks!
>
> On Thursday, April 5, 2012 1:30:50 PM UTC-4, Ben Noordhuis wrote:
>>
>> On Thu, Apr 5, 2012 at 19:07, Paul Selden <[email protected]> wrote:
>> >
>> > On Thursday, April 5, 2012 11:23:08 AM UTC-4, Ben Noordhuis wrote:
>> >>
>> >> On Thu, Apr 5, 2012 at 15:48, Paul Selden <[email protected]> wrote:
>> >> > I'm using: https://github.com/mikeal/request/blob/master/forever.js
>> as
>> >> > an
>> >> > agent in a project that uses a service-oriented-architecture
>> (currently
>> >> > over
>> >> > HTTP) in order to maximize the chance that the connections are kept
>> >> > alive
>> >> > (note, I'm not using the entire request module, just that agent).
>> >> >
>> >> > ...<snip>....
>> >> > options.agent = new ForeverAgent({ minSockets: 100, maxSockets:
>> 100});
>> >> > var req = http.request(options, function (res) {
>> >> > ...<snip>...
>> >> > });
>> >> >
>> >> > req.setTimeout(timeout, function(){ req.abort(); });
>> >> >
>> >> > As more calls are made, it seems to "accumulate" the timeouts for the
>> >> > underlying socket as it is being re-used and I eventually get this
>> >> > error:
>> >> >
>> >> > [2012-04-05 09:21:07.144] [ERROR] console - (node) warning: possible
>> >> > EventEmitter memory leak detected. 11 listeners added. Use
>> >> > emitter.setMaxListeners() to increase limit.
>> >> > [2012-04-05 09:21:07.146] [ERROR] console - Trace:
>> >> > at Socket.<anonymous> (events.js:139:15)
>> >> > at Socket.once (events.js:160:8)
>> >> > at Socket.setTimeout (net.js:143:12)
>> >> > at ClientRequest.<anonymous> (http.js:1287:29)
>> >> > at ClientRequest.g (events.js:156:14)
>> >> > at ClientRequest.emit (events.js:88:20)
>> >> > at Array.0 (http.js:1273:9)
>> >> > at EventEmitter._tickCallback (node.js:192:40)
>> >> >
>> >> > Is this a bug with the forever agent, the http module, or something
>> that
>> >> > I
>> >> > need to unbind myself after a request is finished?
>> >>
>> >> It's documented so it's not a bug. :-)
>> >>
>> >> When you add a callback, it gets registered as a listener for the
>> >> 'timeout' event with EventEmitter.prototype.once(). If you keep
>> >> registering listeners, you'll hit the max listeners limit.
>> >
>> >
>> > Then is this something I can unbind manually if the timeout isn't hit
>> during
>> > a particular request?
>>
>> Yes, that's correct.
>>
>
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en