Closed duythinht closed 8 years ago
A possible workaround wold be to remove the listeners once you finish with them as follows:
return new Promise(function (resolve, reject) {
stream.on('readable', onreadable)
stream.on('error', onerror)
stream.on('end', cleanup)
// define all functions in scope
// so they can be referenced by cleanup and vice-versa
function onreadable() {
cleanup()
resolve(stream.read())
}
function onerror(err) {
cleanup()
reject(err)
}
function cleanup() {
// remove all event listeners created in this promise
stream.removeListener('readable', onreadable)
stream.removeListener('error', onerror)
stream.removeListener('end', cleanup)
}
})
I ran into a similar issue. I also discovered that if you create multiple requests in a row without waiting until the first one performs an actual connection, http2 will create multiple independent connections to the server instead of just one. In your first example you risk creating up to 1000 connections to api.twitter.com. I believe that's not a bug though. This must be happening because at the moment you create requests it's not yet known whether the destination server supports HTTP 2.0. I'd appreciate if @molnarg could confirm or disprove my assumption.
Dupe of #181
I have built a worker, which call a lot of request to http2 server (1 request per message over rabbitmq), so I get memory leak at worker. When I try write a raw code like above, I get node warning
I would like to hear you opinion