You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Making several http requests using keep-alive mode generates this trace: Warning: Possible EventEmitter memory leak detected. #9268
When making 20 http requests using keep-alive mode with node v6.9.1, I get the following trace:
Warning: Possible EventEmitter memory leak detected. 11 timeout listeners added. Use emitter.setMaxListeners() to increase limit
@bnoordhuis I've removed the third-party module in the example and added some memory usage information, because we think that we experience the same problem in our setup.
And just as @arnaud-soulard reported we get a memory leak warning and an actual memory leak in 6.9.1 when using timeouts and keepAlive. This is the output from 6.9.1:
I'm seeing this too - we moved from 4.x to 6.9 the other day and have been seeing crashing due to memory. I spent today chasing it down and found that simply turning off keepalive when creating our Agent (which we pass to https://github.com/request/request with maxsockets 10) stops the leak.
What's interesting is I still get the Possible EventEmitter memory leak detected warning, just no leak.
if (req.timeout) {
socket.once('timeout', () => req.emit('timeout'));
}
In the case of keepalive, the socket is reused -- so each time a new listener is added () => req.emit('timeout') a closure containing a reference to the existing req object is created and retained.
@evantorrie Same problem, right now I bypass it by not using setTimeout on the request and implementing my own timer that resolves without waiting for the request. I definitely think it should be resolved in LTS as this kind of bug is prone to show up only in production and can be quite the headache to debug
@targos@italoacasas I don't know the process, does landing #9440 also get it into LTS?
I don't see the ticket on the lts-watch-v6.x tagged list (because it's closed I presume), but
the change is not in 6.x yet.
@arnaud-soulard v6.7.0 did not have this bug, you could try that. We rolled back to 6.2.2 but
are considering 6.7.0 as well.
Activity
arnaud-soulard commentedon Oct 25, 2016
httpRequests.js.zip
arnaud-soulard commentedon Oct 25, 2016
I joined httpRequests.js that shows the warning when executed with node v6.9.1 on my platform.
bnoordhuis commentedon Oct 25, 2016
Can you trim down your test case so it doesn't depend on a third-party module? It's allowed (and encouraged) to paste it inline.
arnaud-soulard commentedon Oct 25, 2016
gibfahn commentedon Oct 25, 2016
@arnaud-soulard I edited your comment to format it as js, hope that's ok!
arnaud-soulard commentedon Oct 25, 2016
Thank you very much!
bnoordhuis commentedon Oct 25, 2016
@arnaud-soulard When I said 'third-party module', I was referring to async/mapSeries. Can you remove that from your snippet?
Foosvald commentedon Nov 1, 2016
@bnoordhuis I've removed the third-party module in the example and added some memory usage information, because we think that we experience the same problem in our setup.
This is the code we ran:
And just as @arnaud-soulard reported we get a memory leak warning and an actual memory leak in 6.9.1 when using timeouts and keepAlive. This is the output from 6.9.1:
As you can see we get the warning and then the heapUsed is increasing.
When running with only keepAlive but no timeout we get no warning and no leak:
We tried pinpointing which Node version introduced the leak and found that it's present in 6.8.0 but not in 6.7.0.
Could it have been introduced in c9b59e8?
grahamj commentedon Nov 2, 2016
I'm seeing this too - we moved from 4.x to 6.9 the other day and have been seeing crashing due to memory. I spent today chasing it down and found that simply turning off
keepalivewhen creating ourAgent(which we pass to https://github.com/request/request withmaxsockets10) stops the leak.What's interesting is I still get the
Possible EventEmitter memory leak detectedwarning, just no leak.evantorrie commentedon Nov 18, 2016
The problem is due to this commit: ee7af01
Specifically these three lines of code
node/lib/_http_client.js
Line 565 in ee7af01
In the case of keepalive, the socket is reused -- so each time a new listener is added
() => req.emit('timeout')a closure containing a reference to the existingreqobject is created and retained.This has caused our application major memory leak problems, and appears to have been there since 6.8.1. https://github.com/nodejs/node/tree/v6.8.1
karlbohlmark commentedon Nov 18, 2016
@evantorrie Yup, that's what my pull request addresses. I'm a little bit surprised that a memory leak in the LTS is not given more priority.
We had a bunch of services crash in production after upgrading to 6.9.1.
oiime commentedon Nov 18, 2016
@evantorrie Same problem, right now I bypass it by not using setTimeout on the request and implementing my own timer that resolves without waiting for the request. I definitely think it should be resolved in LTS as this kind of bug is prone to show up only in production and can be quite the headache to debug
targos commentedon Jan 8, 2017
Closing as the fix in #9440 landed.
andrasq commentedon Jan 9, 2017
@targos @italoacasas I don't know the process, does landing #9440 also get it into LTS?
I don't see the ticket on the lts-watch-v6.x tagged list (because it's closed I presume), but
the change is not in 6.x yet.
@arnaud-soulard v6.7.0 did not have this bug, you could try that. We rolled back to 6.2.2 but
are considering 6.7.0 as well.
targos commentedon Jan 9, 2017
The PR is labeled
lts-watch-v6.xso the fix will eventually be cherry-picked to 6.x.andrasq commentedon Jan 9, 2017
Thanks @targos!
pkoretic commentedon Feb 7, 2017
still not cherry-picked in 6.9.5 for those interested, maybe if somebody could speed this up, bad bug for lts really @targos
targos commentedon Feb 7, 2017
It will be in the next release. See #10974
Removed-5an commentedon Mar 1, 2017
Is it possible this is fixed in 6.10 and not 7.5? If this really solves it in 6.10 I can run my application on node 6.10.
karlbohlmark commentedon Mar 1, 2017
@5an1ty This is merged in 6.10