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

Memory leak for https.request() on ECONNRESET #8827

Closed
patrickd- opened this issue Sep 28, 2016 · 11 comments
Closed

Memory leak for https.request() on ECONNRESET #8827

patrickd- opened this issue Sep 28, 2016 · 11 comments
Labels
confirmed-bug Issues with confirmed bugs. https Issues or PRs related to the https subsystem. memory Issues and PRs related to the memory management or memory footprint.

Comments

@patrickd-
Copy link

patrickd- commented Sep 28, 2016

I experience a memory leak when doing https requests to a host that resets the connection.

Reproduce by

  1. starting node econnreset.js
    econnreset.js.txt
  2. start node leak.js
    leak.js.txt
  3. Observe process memory
    For me it goes up to 600MB with 10000 requests - and stays that way.

Heapdump is small

  1. install node-heapdump (npm install heapdump)
  2. comment in the require('heapdump')
  3. run node econnreset.js and node leak.js
  4. when it's done with the requests (no more CPU usage) execute kill -USR2 $pid.
    The resulting heapdump from a process with 600MB is only 100MB large.

Manual GC call has no effect

  1. comment in global.gc();
  2. start node econnreset.js and node leak.js --expose-gc
  3. when it's done with the requests (no more CPU usage) it will execute the GC every second but the memory usage doesn't change.

Am I using https.request() wrong or is this an internal problem?

@addaleax addaleax added the https Issues or PRs related to the https subsystem. label Sep 28, 2016
@mscdex mscdex added the memory Issues and PRs related to the memory management or memory footprint. label Sep 28, 2016
@imyller
Copy link
Member

imyller commented Oct 7, 2016

I have not verified, but there is a possibility that this is related to #8647 - which is not in 6.7.0

@patrickd-
Copy link
Author

unfortunately I'm still able to reproduce this bug with node 6.8.0

@patrickd-
Copy link
Author

also able to reproduce in 7.0.0

@bnoordhuis
Copy link
Member

I had a look and it's a variation on #8871 (comment). Abridged version: catastrophic memory fragmentation because of how glibc allocates memory. There isn't much we can do about that except switch to a different memory allocator and that is not a trivial undertaking.

If you strace -o trace.log -e brk node leak.js, you will find that the brk addresses only go up, never down. On my FC24 x86_64 system, the difference between the lowest and the highest address is almost exactly 700 MB.

@bnoordhuis bnoordhuis added the confirmed-bug Issues with confirmed bugs. label Nov 3, 2016
@patrickd-
Copy link
Author

This seems to have been fixed by node version 7.2.0 (probably #9626)

Can no longer reproduce, closing

@tsheaff
Copy link

tsheaff commented Apr 24, 2017

For me this issue was still present in v7.7.4, but fixed in v7.9.0. For posterity:

This code causes a large leak (50kb per call which adds up quickly on production):

request.get({ url: 'https://www.google.com' });

This code does not leak (https changed to http):

request.get({ url: 'http://www.google.com' });

using request package

I wish the bug had been better documented — was a critical one in our case as it took our server out of memory about once an hour.

@itslukej
Copy link

I'm able to reproduce this on v7.9.0

@bnoordhuis
Copy link
Member

@itslukej Please file a new issue and include steps to reproduce.

@pizzachip
Copy link

Using http seems to slow down the leak for me vs https, but, it still leaks on v8.9.1

@knoxcard
Copy link

This ticket needs to be reopened?

@knoxcard
Copy link

Wonder if this can be resolved by using this instead???

https://github.com/request/request-promise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. https Issues or PRs related to the https subsystem. memory Issues and PRs related to the memory management or memory footprint.
Projects
None yet
Development

No branches or pull requests

9 participants