Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response strings and closures objects leak with http.Agent enabled (Memory Leak) #9530

Closed
snow01 opened this issue Nov 9, 2016 · 6 comments
Labels
http Issues or PRs related to the http subsystem.

Comments

@snow01
Copy link

snow01 commented Nov 9, 2016

  • 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 --

  1. With http.Agent enabled, strings delta is 10 Mb. From Retainers tab it is clear that these objects are from http requests.

screenshot 2016-11-09 22 38 46

  1. With http.Agent enabled, closures delta is 0.5 Mb. From Retainers tab it is clear that these closures are from http requests.

screenshot 2016-11-09 22 39 10

  1. Without http.Agent, there is no positive delta for strings and closures

screenshot 2016-11-09 22 39 26

Please guide how can I help quick resolution of this issue.

@mscdex mscdex added the http Issues or PRs related to the http subsystem. label Nov 9, 2016
@snow01
Copy link
Author

snow01 commented Nov 15, 2016

Any update on this issue ?

@bnoordhuis
Copy link
Member

You should post a standalone (no third-party modules) test case if you want people to take a look.

@snow01
Copy link
Author

snow01 commented Nov 16, 2016

@bnoordhuis - is http.Agent a third party module for NodeJS ? Are there any existing http performance tests I can adapt ?

@bnoordhuis
Copy link
Member

http.Agent is built-in. You can find performance tests in benchmark/http.

@andrasq
Copy link

andrasq commented Nov 18, 2016

I recently came across this same issue (memory leak in 6.9.1 that's not there in 6.2.2) that I too
traced to _http_agent. On the above screenshots, notice how the 'timeout' event handlers array
in Agent.freesockets localhost:9200 is 173 entries deep.

I then came across PR#9440 (#9440) which fixes it.
Turns out _http_client is re-adding a timeout listener on reused sockets on every request.
The PR is a small fix that removes the timeout listener on response end.

Agent is not at fault, but it is the one that's retaining the sockets. The sockets accrue callbacks,
and the callbacks are bound to the (annotated by the app, possibly very large) request objects.

@Trott
Copy link
Member

Trott commented Jul 15, 2017

I infer from the fact that #9440 landed that this can be closed. Please let me know if that's incorrect. Closing now. Thanks!

@Trott Trott closed this as completed Jul 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem.
Projects
None yet
Development

No branches or pull requests

5 participants