GeezerVison is showing github.com — Memory usage (external) reports a negative value? · Issue #21570 · nodejs/node
Memory usage (external) reports a negative value? #21570Labels httpsIssues and PRs related to the https subsystem.memoryIssues and PRs related to Node.js memory management or memory footprint. Description
Running some http server process in node.js in REPL environment (under tmux), the function: process.memoryUsage() function can return a negative value. Is that a bug? The process (server) was run for many days, and I sometimes use process.memoryUsage() to check the values and I found:
> process.memoryUsage()
{ rss: 33452032,
heapTotal: 9031680,
heapUsed: 5112064,
external: -503806 }
The external memory is negative, but it was still postive 2 days ago when I checked. Notes, I run the node.js with flags:
--expose-gc --max-old-space-size=256
This is running on a Raspberry Pi ZERO W.
Activityadded processIssues and PRs related to the process subsystem. memoryIssues and PRs related to Node.js memory management or memory footprint. on Jun 28, 2018bnoordhuis commented on Jun 28, 2018 That probably means you're using an add-on (a native module) with a bug in it - it's miscalling v8::Isolate::AdjustAmountOfExternalAllocatedMemory().
If you can track this down to Node.js core (i.e., exclude add-ons), let me know and I'll reopen. bertlea commented on Jun 28, 2018 OK, I will try to remove all external modules and run the basic functions of the server to try. However, I did not observed that issue on the identical server code ran on version 6.x.x and 8.x.x. Anyway, I will try to run a sample cut-down server without any external module. bertlea commented on Jun 29, 2018 @bnoordhuis I track it down that it got the issue in Node.js core. I can replicate the case that I can have negative external memory from "process.memoryUsage()" call. The situation is simple: You keep making an https GET request to get some contents from a server and do a frequenct gc() call (the V8 garbage collection call), then the external memory reported will going down even keep going even the value is negative.
I think it affects version 10.4.x (may be earlier) to 10.5.0 (latest version) on at least both Windows 64-bit version and the arm v6l version. I suspect it affects all platforms. I found it do not affect v10.1.0 and earlier version. A simple but not very clean code can show the issue:
Notes: http seems not affected, and also you need to run it with --expose-gc flag.
const https = require('https');
function getip() {
https.get('https://api.ipify.org', (resp) => {
let data = '';
resp.on('data', (chunk) => data += chunk);
resp.on('end', () => console.log(`data: ${data} ext mem: ${process.memoryUsage().external}`));
resp.on('error', (err) => console.log('error: ' + err.message));
});
gc();
}
if(typeof gc !== 'function') {
console.log('gc is not enabled, use --expose-gc flag to run.');
process.exit();
}
setInterval(getip, 3000); //get ip every 3 seconds
console.log('test started. expecting out every 3 seconds. Ctr-c to quit.');
bertlea commented on Jun 29, 2018 Clarification: The issue I tested is at the "client" side that making HTTPS request, not at the server side. added httpsIssues and PRs related to the https subsystem. and removed processIssues and PRs related to the process subsystem. on Jun 29, 2018bnoordhuis commented on Jun 29, 2018 Thanks, reopened and labels updated. Reacted by Nikita Skovoroda and bertlea bertlea commented on Jul 4, 2018 Updated the sample code to demo the issue with a simpler code using a public HTTPS service. bertlea commented on Aug 9, 2018 @bnoordhuis Just curious if this is not yet classified as a bug so nobody is looking at it? Or it is low priority and just waiting in some queues? I am not familiar with the process here, but I agree it is not high-priority as it seems not breaking anything other than reporting negative memory sizes. logidelic commented on Aug 29, 2018 FWIW, I've been seeing this on Node 10.9 as well. mafintosh commented on Aug 30, 2018 Yea I've hit this multiple times as well. Made a fix here, #22594 Trott commented on Nov 29, 2018 Presumably fixed in 1287e52 which first appeared in Node.js 11.0.0. Please comment (or re-open if GitHub lets you) if you are experiencing this bug with a version of Node.js that is 11.x or newer.
MetadataMetadatahttpsIssues and PRs related to the https subsystem.memoryIssues and PRs related to Node.js memory management or memory footprint. DevelopmentNo branches or pull requestsIssue actions
|