question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory leak with puppeteer

See original GitHub issue

Tell us about your environment:

Puppeteer version: Latest Platform / OS version: Windows 10 URLs (if applicable): any Node.js version: v8.11.2

What steps will reproduce the problem?

I’ve made an automation that run once a hour and clicks on different buttons on a page. I’ve run the script in non headless mode for hours and the browser is being closed completely and no issues are detected in the code. But for some reason after a couple of days it says my memory usage is at 98% while there is no service that uses that memory not in Task Manager and not even in RAMMAP

Please include code that reproduces the issue.

The code is use to run the bot every half a hour looks like that: (the BotClass is a set of the puppeteer commands and browser creation , which is being closed completly after every use)

function createUser(username, callback) {

    con.query('SELECT * FROM bots WHERE username = ?', [username], function (err, result) {
        if (err) return callback(err); // Traditional error-first callback
        let user = new botClass(result[0]);
        callback(null, user);
    });
}

function sleep(ms) {
    return new Promise(resolve => {
        setTimeout(resolve, ms)
    })
}

async function start() {
    let userNames;
    con.query("SELECT username FROM bots WHERE active = ?", "true", function (err, result, fields) {
        if (err) throw err;
        userNames = result;
    });
    await sleep(2000);
    await console.log(userNames);
    for (let i = 0; i < userNames.length; i++) {
        try {
            await createUser(userNames[i].username, function (err, user) {
                    if (err) throw err;
                    user.login();
                    user = null;
                    console.log("\n\nUser Deleted\n\n")
                }
            );
            await sleep(120000);
        }
        catch (e) {
            console.log(e);
            console.log("there was an error with user " + userNames[i]);
        }
    }
    setTimeout(start, 1800000);
}

start();

What is the expected result?

Not use 98% of the memory after 48h of running

What happens instead?

The script is being closed after 48h due to not enough memory and the memory does not free at all so I have to restart my pc every time

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
ingsunikicommented, Jun 17, 2020

I encountered a problem about time scheduling in a repeat for several url pages once or alternately, but he could not run as it should be, various methods have been taken and finally can run only by using an import and export module function and then running with the cron node , but a new problem arises because he cannot use the browser.close () function, but can only use page.close which results in a memory leak because when I use browser.close () then the next process he will not be able to open the browser in next process, is there anyone who can help

0reactions
stale[bot]commented, Jul 26, 2022

We are closing this issue. If the issue still persists in the latest version of Puppeteer, please reopen the issue and update the description. We will try our best to accomodate it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to simply workaround RAM-leaking libraries like ...
Universal fix for RAM leaks issues. So here is a very simple idea which works great in all such cases: Instead of importing...
Read more >
Chrome memory leak · Issue #5893 · puppeteer ... - GitHub
I was able to recreate the memory leak issue again via browser.newPage() and having more than 1 user generates PDFs. We are just...
Read more >
Automatically detect memory leaks with Puppeteer
In general a memory leak is the situation in which a software holds on to a piece of memory which it doesn't really...
Read more >
Puppeteer: memory leak error and timeout handling
I am trying to scrape the data from this site. Below is the code, which is working for single district and hospital type...
Read more >
How to fix RAM-leaking libraries like Puppeteer easily ... - Reddit
Instead of importing and using library in your main process, you move the puppeteer code completely to a small child process.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found