-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Memory leak with https request #221
Comments
This seems to be caused by something going wrong with the process of adding credentials in (if you didn't provide them). If I create credentials with crypto then reuse them for my HTTPS requests the leak doesn't exist. http://github.com/ry/node/blob/master/src/node_crypto.cc#L191 |
updated test for v0.4.3
|
+1 on this bug, I'm seeing similar results. (v0.4.8) |
Is this still an issue with master? Ryan's test case shows RSS going up and down here. Tested with |
+1 with 0.4.9 |
This isn't a memory leak. It's a GC issue. I modified the code @ry did to try this: var https = require('https');
process.title = 'http-mem-test';
var count = 0;
function request() {
https.get({ host: 'google.com' }, function() {
if(count > 1000) {
clearInterval(interval)
//keep process open while GC happens
var stdin = process.openStdin();
} else {
count += 1;
}
});
}
var mem = null;
function report_stats() {
var temp = process.memoryUsage();
if (!mem) mem = temp;
var diff = (temp.rss - mem.rss) / (1024*1024);
console.log((temp.rss)/(1024*1024) +
" Mb memory usage, diff "+ diff + " Mb");
mem = temp;
}
setInterval(report_stats, 3*1000);
var interval = setInterval(request, 1000); It takes a while but v8 finally GCs down to less than the initial memory count from the first report_stats interval. |
Not true in my case. Started at 12.95703125 Mb at 11am. Stopped at 82.9765625 Mb at 7pm. |
Which test case were you using mine or Ry's? Are you using head? Mine stops making requests after 1000 reqs to allow the GC to catch up. I think the point is that if you use a lot of https client requests you eat up memory faster than it can be GC'd. However it isn't actually leaking. I'm not saying we shouldn't try to optimize but I can't see an actual leak. |
With your testcase:
|
This was a bit of a pain to figure out. https://gist.github.com/1308628 Updated test case it takes almost an hour for v8 to clean up the memory. Maybe someone with a better understanding of the VM could shed some light on that. |
Is there a fix or workaround for this issue? |
Undecided. I'm not able to reproduce it in a reasonable time frame (say 30 minutes). The growing memory footprint you're seeing may be the result of V8 growing the heap in order to reduce mark-and-sweep cycles. Do you get an OOM error when you cap the heap size with e.g. --max_old_space_size=75? What does the heap look like when you take a snapshot with https://github.com/bnoordhuis/node-heapdump ? |
@bnoordhuis The size of Just to note: I ran the script with |
Yes, that's expected (or, at least, not unexpected) behavior. max_old_space_size controls the size of the V8 heap, it doesn't affect allocations made by node's binding layer (e.g. buffers). I looked some more into it and I'm convinced there's no memory leak any more (assuming there ever was one). Here is a slightly modified test case: var https = require('https');
function request() {
https.get({ host: 'google.com' });
}
var mem = null;
var fs = require('fs');
function rss() {
var pages = fs.readFileSync('/proc/self/stat', 'ascii').split(' ')[23];
return { rss: 4096 * pages };
}
function report_stats() {
if (typeof gc === 'function') gc();
var temp = rss();
if (!mem) mem = temp;
var diff = (temp.rss - mem.rss) / (1024*1024);
console.log((temp.rss)/(1024*1024) +
" Mb memory usage, diff "+ diff + " Mb");
mem = temp;
}
setInterval(report_stats, 3*1000);
setInterval(request, 1000); Run it with
The reason the test calls fs.readFileSync('/proc/self/stat') instead of process.memoryUsage() is that the latter calls fopen("/proc/self/stat") which in turns calls mmap(). mmap() modifies the process' page mappings and that changes the RSS (because RSS on modern operating system represents the section of virtual address space that's currently in use). One more reason why it's a bad indicator of memory leaks. |
Hi,
I have discovered a memory leak when create https request. Memory increased all the time.
It works fine with http request.
You can see the tescase: http://gist.github.com/493929
The text was updated successfully, but these errors were encountered: