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

How can i disable puppeteer dev profile. #1791

Closed
bahattincinic opened this issue Jan 12, 2018 · 15 comments
Closed

How can i disable puppeteer dev profile. #1791

bahattincinic opened this issue Jan 12, 2018 · 15 comments

Comments

@bahattincinic
Copy link

Environment:
Puppeteer version: 0.11.0
Platform / OS version: AWS Lambda
Node.js version: 6.10

Puppeteer Arguments

puppeteer.launch({
  args: ['--disable-gpu', '--no-sandbox', '--single-process', 
             '--disable-web-security', '--disable-dev-profile']
});

Hello,

We are using puppeteer on AWS Lambda. It handles over 10 million requests every month.

When we were trying to handle concurrent requests, puppeteer returned this error:

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1383):
Error: ENOSPC: no space left on device, mkdtemp '/tmp/puppeteer_dev_profile-XXXXXX'

I tried to disable dev profile with the --disable-dev-profile argument. But it doesn't work.

How can I do it?

@aslushnikov
Copy link
Contributor

It handles over 10 million requests every month.

That's impressive, thanks for sharing.

I tried to disable dev profile with the --disable-dev-profile argument. But it doesn't work.
How can I do it?

@bahattincinic i'm afraid there's no way to, at least none I'm aware of. Chrome needs some place to store profile data.

if there's not enough space on the tmp location, you can pass your own data directory with userDataDir option to pptr launch.

If you're short on disk space but have plenty of RAM, you can mount a tmpfs and use it for profile directories.

@bahattincinic
Copy link
Author

bahattincinic commented Jan 12, 2018

@aslushnikov Thank you for your quick answer.

When I checked /tmp folder in the Lambda, I saw puppeteer doesn't remove profile file.

Example Output:

2018-01-12T14:55:38.553Z    a6ef3454-f7a8-11e7-be0f-17f405d5a180    start stdout: total 226084
drwx------ 3 sbx_user1067 479 4096 Jan 12 14:55 .
drwxr-xr-x 21 root root 4096 Jan 12 10:53 ..
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:33 core.headless-chromi.129
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:15 core.headless-chromi.131
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:49 core.headless-chromi.135
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:52 core.headless-chromi.137
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:50 core.headless-chromi.138
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:51 core.headless-chromi.14
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:49 core.headless-chromi.15
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:36 core.headless-chromi.169
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:15 core.headless-chromi.174
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:52 core.headless-chromi.178
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:50 core.headless-chromi.180
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:48 core.headless-chromi.181
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:36 core.headless-chromi.210
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:52 core.headless-chromi.217
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:19 core.headless-chromi.218
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:50 core.headless-chromi.223
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:48 core.headless-chromi.224
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:38 core.headless-chromi.250
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:21 core.headless-chromi.255
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:53 core.headless-chromi.259
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:50 core.headless-chromi.263
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:48 core.headless-chromi.265
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:40 core.headless-chromi.290
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:22 core.headless-chromi.297
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:55 core.headless-chromi.302
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:50 core.headless-chromi.306
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:48 core.headless-chromi.307
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:42 core.headless-chromi.331
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:55 core.headless-chromi.340
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:50 core.headless-chromi.346
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:42 core.headless-chromi.376
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:50 core.headless-chromi.387
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:45 core.headless-chromi.420
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:51 core.headless-chromi.430
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:45 core.headless-chromi.464
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:51 core.headless-chromi.468
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:46 core.headless-chromi.504
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:51 core.headless-chromi.507
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:51 core.headless-chromi.51
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:31 core.headless-chromi.53
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:49 core.headless-chromi.54
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:46 core.headless-chromi.549
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:49 core.headless-chromi.55
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:51 core.headless-chromi.56
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:47 core.headless-chromi.58
-rw------- 1 sbx_user1067 479 15159296 Jan 12 14:46 core.headless-chromi.590
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:47 core.headless-chromi.629
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:47 core.headless-chromi.672
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:47 core.headless-chromi.711
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:47 core.headless-chromi.749
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:31 core.headless-chromi.92
-rw------- 1 sbx_user1067 479 15159296 Jan 12 14:49 core.headless-chromi.94
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:52 core.headless-chromi.95
-rw------- 1 sbx_user1067 479 15126528 Jan 12 14:47 core.headless-chromi.96
drwx------ 3 sbx_user1067 479 4096 Jan 12 14:14 .pki

Why puppeteer/chrome doesn't remove profile file after close it ?

I don't want to create any file on lambda. is it possible to pass dummy/static profile file to puppeteer?

If you're short on disk space but have plenty of RAM, you can mount a tmpfs and use it for profile directories.

I'm not sure about it. Because AWS Lambda containers don’t have a tmpfs mount support.

if there's not enough space on the tmp location, you can pass your own data directory with userDataDir option to pptr launch.

I think only /tmp folder writable in the lambda.

@aslushnikov
Copy link
Contributor

Why puppeteer/chrome doesn't remove profile file after close it ?

@bahattincinic This seems to be the real issue. Is this the output of ls /tmp that you posted? The core.headless-chrome doesn't seem to be a leftover from a user profile; it's something OS related.

@bahattincinic
Copy link
Author

bahattincinic commented Jan 12, 2018

Is this the output of ls /tmp that you posted?

Yes, ls -al /tmp output.

The core.headless-chrome doesn't seem to be a leftover from a user profile; it's something OS related.

I passed dev/null value to userDataDir option. it worked on the mac. But lambda Disk usage continues to grow.

I upgraded chrome version to 64. but the result is still same.

That's why I agree with you. it doesn't relate to profile file.

When I analyzed this file, I saw the following output: (it looks like a core dump)

tmp/core.headless-chromi.65: ELF 64-bit LSB core file x86-64, version 1 (SYSV), SVR4-style, from 'bin/headless-chromium --disable-background-networking --disable-background-time

Do you have any idea @aslushnikov?

@bahattincinic
Copy link
Author

@aslushnikov We fixed this bug.

When the problem occurred, OS copies binary (chrome binary) core dump to /tmp folder. We removed this files after processing. Actually, we don't understand why OS copied it. We will talk about it with AWS support.

We realized that lambda was not the right choice. (RAM limits, Disk Limits, hard to debug, Shared Disk space, concurrency limits...)

@aslushnikov Thanks for your great support.

@jborden13
Copy link

@bahattincinic can you share your code that you used to clear the /tmp folder? I've tried it a million different ways and still am constantly running into:

Error: ENOSPC: no space left on device, mkdtemp '/tmp/puppeteer_dev_profile-XXXXXX'

@pixelport
Copy link

@jborden13

Here is my solution. The advantage of this is that you can run multiple puperteer instances in parallel. Because only the puppeteer_dev_profile of the current instance is deleted after the browser is closed.

let fs = require('fs-extra');
const puppeteer = require('puppeteer');

let browser = await puppeteer.launch();
let chromeTmpDataDir = null;

// find chrome user data dir (puppeteer_dev_profile-XXXXX) to delete it after it had been used
let chromeSpawnArgs = browser.process().spawnargs;
for (let i = 0; i < chromeSpawnArgs.length; i++) {
    if (chromeSpawnArgs[i].indexOf("--user-data-dir=") === 0) {
        chromeTmpDataDir = chromeSpawnArgs[i].replace("--user-data-dir=", "");
    }
}

// ...

browser.close();

if (chromeTmpDataDir !== null) {
    fs.removeSync(chromeTmpDataDir);
}

process.exit(0);

@imzisy
Copy link

imzisy commented Apr 22, 2018

Hi @pixelport ,

I'm getting this error

/var/folders/v1/7968py454sndddyv845p0fwh0000gn/T/puppeteer_dev_profile-4m5csR
{ Error: ENOTEMPTY: directory not empty, rmdir '/var/folders/v1/7968py454sndddyv845p0fwh0000gn/T/puppeteer_dev_profile-4m5csR/Default'
at Object.fs.rmdirSync (fs.js:846:18)
at rmkidsSync (/Users/emad/Desktop/traveloka-service/dist/node_modules/fs-extra/lib/remove/rimraf.js:304:27)
at rmdirSync (/Users/emad/Desktop/traveloka-service/dist/node_modules/fs-extra/lib/remove/rimraf.js:281:7)
at rimrafSync (/Users/emad/Desktop/traveloka-service/dist/node_modules/fs-extra/lib/remove/rimraf.js:252:7)
at options.readdirSync.forEach.f (/Users/emad/Desktop/traveloka-service/dist/node_modules/fs-extra/lib/remove/rimraf.js:291:39)
at Array.forEach ()
at rmkidsSync (/Users/emad/Desktop/traveloka-service/dist/node_modules/fs-extra/lib/remove/rimraf.js:291:26)
at rmdirSync (/Users/emad/Desktop/traveloka-service/dist/node_modules/fs-extra/lib/remove/rimraf.js:281:7)
at Object.rimrafSync [as removeSync] (/Users/emad/Desktop/traveloka-service/dist/node_modules/fs-extra/lib/remove/rimraf.js:252:7)
at Object. (/Users/emad/Desktop/traveloka-service/dist/index.js:407:10)
errno: -66,
code: 'ENOTEMPTY',
syscall: 'rmdir',
path: '/var/folders/v1/7968py454sndddyv845p0fwh0000gn/T/puppeteer_dev_profile-4m5csR/Default' }

@pguardiario
Copy link

Is there a solution to dev profiles not getting removed? This has been an ongoing issue for me for years now.

@gencoglutugrul
Copy link

I've been struggling with same issue.
I randomly get this error

Warning: Failure writing file /tmp/puppeteer_dev_profile-xJNRrv/Default/Preferences {
  target: 'Profile',
  file: 'Preferences',
  contents: '{\n  "intl": {\n    "accept_languages": "en-US,en"\n  }\n}'
} [Error: ENOENT: no such file or directory, open '/tmp/puppeteer_dev_profile-xJNRrv/Default/Preferences'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/tmp/puppeteer_dev_profile-xJNRrv/Default/Preferences'
}

It's not because of available disk space, because i have ~100GB free.
Also it's not because of the permissions, because i don't get this error all the time.

@zerosdev
Copy link

@jborden13

Here is my solution. The advantage of this is that you can run multiple puperteer instances in parallel. Because only the puppeteer_dev_profile of the current instance is deleted after the browser is closed.

let fs = require('fs-extra');
const puppeteer = require('puppeteer');

let browser = await puppeteer.launch();
let chromeTmpDataDir = null;

// find chrome user data dir (puppeteer_dev_profile-XXXXX) to delete it after it had been used
let chromeSpawnArgs = browser.process().spawnargs;
for (let i = 0; i < chromeSpawnArgs.length; i++) {
    if (chromeSpawnArgs[i].indexOf("--user-data-dir=") === 0) {
        chromeTmpDataDir = chromeSpawnArgs[i].replace("--user-data-dir=", "");
    }
}

// ...

browser.close();

if (chromeTmpDataDir !== null) {
    fs.removeSync(chromeTmpDataDir);
}

process.exit(0);

Finally, you saved my life. I ran out of 100GB space because of this problem

@The-East-Wind
Copy link

I've been facing the same issue with a node.js application that uses puppeteer while running in a container. Using the --disable-dev-shm-usage flag solved the problem of core dump files getting created and exhausting disk space.

@mbonaci
Copy link

mbonaci commented Sep 24, 2023

@The-East-Wind I already had that flag from before, which apparently has not prevented this issue.
The creation of these dev profiles started happening after I upgraded Puppeteer to the latest version (v21).

@andrii-pukhalevych
Copy link

Dev profile files are not deleted in case of unhandled exceptions, so browser.close() is not called.
Can be fixed with with try catch:

let browser = await puppeteer.launch();

try {
	const context = await browser.createIncognitoBrowserContext();
	const page = await context.newPage();
	await page.goto(url);
....
} catch (e) {
	process.exitCode = 1
	console.error(e);
}

browser.close();

@gregg-cbs
Copy link

Can anyone verify that the above try catch has solved the bloating of dev profiles in tmp folder?

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