Memory leak with puppeteer
See original GitHub issueTell 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:
- Created 4 years ago
- Comments:6
Top GitHub Comments
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
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!