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 usage (external) reports a negative value? #21570

Closed
bertlea opened this issue Jun 28, 2018 · 10 comments
Closed

Memory usage (external) reports a negative value? #21570

bertlea opened this issue Jun 28, 2018 · 10 comments
Labels
https Issues or PRs related to the https subsystem. memory Issues and PRs related to the memory management or memory footprint.

Comments

@bertlea
Copy link

bertlea commented Jun 28, 2018

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.


@vsemozhetbyt vsemozhetbyt added process Issues and PRs related to the process subsystem. memory Issues and PRs related to the memory management or memory footprint. labels Jun 28, 2018
@bnoordhuis
Copy link
Member

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
Copy link
Author

bertlea commented 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
Copy link
Author

bertlea commented 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
Copy link
Author

bertlea commented Jun 29, 2018

Clarification: The issue I tested is at the "client" side that making HTTPS request, not at the server side.

@bnoordhuis bnoordhuis added https Issues or PRs related to the https subsystem. and removed process Issues and PRs related to the process subsystem. labels Jun 29, 2018
@bnoordhuis
Copy link
Member

Thanks, reopened and labels updated.

@bnoordhuis bnoordhuis reopened this Jun 29, 2018
@bertlea
Copy link
Author

bertlea commented Jul 4, 2018

Updated the sample code to demo the issue with a simpler code using a public HTTPS service.

@bertlea
Copy link
Author

bertlea commented 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
Copy link

FWIW, I've been seeing this on Node 10.9 as well.

@mafintosh
Copy link
Member

Yea I've hit this multiple times as well. Made a fix here, #22594

@Trott
Copy link
Member

Trott commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

Successfully merging a pull request may close this issue.

6 participants