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

Weird memory leak #2351

Closed
OmgImAlexis opened this issue Dec 12, 2019 · 7 comments
Closed

Weird memory leak #2351

OmgImAlexis opened this issue Dec 12, 2019 · 7 comments

Comments

@OmgImAlexis
Copy link

OmgImAlexis commented Dec 12, 2019

  • Node.js Version: v10.16.3
  • OS: Unraid 6.8 (stable)
  • Scope (install, code, runtime, meta, other?): (not sure on what this means?)
  • Module (and version) (if relevant):
  • Extra: I'm using node --optimize_for_size index.js to start my app.

I'm still not sure what's causing this and the issue seems to be buried somewhere within my app. I've tried disabling large sections of the app with some success but the leak just seems to randomly appear again.

I've tried using things such as njstrace to see what's running while the memory is increasing and I never see any functions running. Same goes for using chrome's devtools and debugger statements. Basically comes down to there not being any code run yet memory is increasing. Since I'm not sure what's running I can't find where the leak is. One though I had was it's leaking in a timer somewhere and the tracing methods I've tried aren't catching it?

As you can see the heap seems to recover but RSS continues to grow.

Screen Shot 2019-12-12 at 4 04 19 pm

This is the script I'm using the log the data. It just outputs as | separated and then I put the data into google sheets for the graph. From what I can tell the logMemory function isn't causing any issues.

const fs = require('fs');
const logPath = require('path').resolve(__dirname, 'memory.log');

const logMemory = () => {
    gc();
    const memory = process.memoryUsage();
    fs.appendFile(logPath, `${memory.rss}|${memory.heapTotal}|${memory.heapUsed}|${memory.external}\n`, err => {
        if (err) {
            throw err;
        }
    });
};

setInterval(logMemory, 1000);
@OmgImAlexis
Copy link
Author

Just documenting things I've tried.

  1. As per All NodeJS apps on my server are leaking memory #947 (comment) I tried adding --turbo_filter="" to my start script so I'm now using node --turbo_filter="" --optimize_for_size index.js and I get this output. I'm still running this so the results may change but this looks positive so far. Granted I have no clue what this changed as I can't find much info on turbo_filter.

Screen Shot 2019-12-12 at 4 35 59 pm

@OmgImAlexis
Copy link
Author

This is the same graph as above but with more data. The one above is only the first 5 mins, this is roughly 20 mins including that.

Screen Shot 2019-12-12 at 4 53 34 pm

@OmgImAlexis
Copy link
Author

The peak you're seeing is me connecting and then disconnecting a client. You can see a similar peak on the first graph.

@gireeshpunathil
Copy link
Member

@OmgImAlexis -

  • what is the scale in the X-axis of your graph?
  • taking heap statistics in every second is fine, but doing gc / second is not a good practice?
  • I would recommend you collecting 3 or 4 heapdumps and see which objects are growing - a couple of those taken when the usage is steady (or the first phase in your graph), and a couple when there is a growth (again when the graph stabilizes to the new heights, not the spike. Sorry, I am unable to better point locations in your graph, without the X-axis milestones.)

@OmgImAlexis
Copy link
Author

Every point is 1s. I can provide the raw data if that helps?

Okay, I'll give that a go and get back to you.

@gireeshpunathil
Copy link
Member

@OmgImAlexis - ay updates on this?

Refs: nodejs/node#31641 , that also reports a potential reason for fake RSS growth.

@gireeshpunathil
Copy link
Member

closing as inactive, pls reopen if this is outstanding, and when you can provide details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants