Description
- Version: v6.9.1
- Platform: Linux ip-172-31-46-151 4.4.11-23.53.amzn1.x86_64 deps: update openssl to 1.0.1j #1 SMP Wed Jun 1 22:22:50 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
- Subsystem: Http(s) Agent
http.Agent based sockets pool is leading to memory leaks. With http.Agent enabled, both response strings and response handlers (closures) are not getting released so quickly -- all these objects and closures are getting promoted to old generation. Even on a normal load of 2-3 requests per second, garbage collection is not able to free these promoted objects an closures, application's memory usage reaches to 1GB in just 10-12 hours of run -- eventually application crashes due to out of memory.
Pool settings are normal --
new http.Agent({
keepAlive: true,
maxSockets: 10,
maxFreeSockets: 5,
keepAliveMsecs: 5000
})
I have done comparison of heap snapshots at various time points to reach to this conclusion. I have even verified that with default agent settings (that is http.globalAgent), I do not see any such behaviour - application memory remains consistent at ~90-95Mb
Below are screenshots from chrome developer tools for various scenarios --
- With http.Agent enabled, strings delta is 10 Mb. From Retainers tab it is clear that these objects are from http requests.
- With http.Agent enabled, closures delta is 0.5 Mb. From Retainers tab it is clear that these closures are from http requests.
- Without http.Agent, there is no positive delta for strings and closures
- I can see similar issue was discussed and reported for 0.x version of NodeJS too - Memory leak using http's request/get/clientRequest and closures node-v0.x-archive#3179
- One of the discussion also suggests that keeping agent disabled worked - Filirom1/node@6730cdc
Please guide how can I help quick resolution of this issue.