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

Puppeteer crash due to dev profile error #19

Open
ringge opened this issue Dec 6, 2023 · 14 comments
Open

Puppeteer crash due to dev profile error #19

ringge opened this issue Dec 6, 2023 · 14 comments

Comments

@ringge
Copy link

ringge commented Dec 6, 2023

I'm running Translateer using Option 2, Serve locally.
After a while, the app crashed and showed below error

`/root/apps/translateer/node_modules/@puppeteer/browsers/lib/cjs/launch.js:271
reject(new Error([
^

Error: Failed to launch the browser process! undefined
[1301414:1301414:1205/220205.443107:ERROR:process_singleton_posix.cc(335)] Failed to create /tmp/puppeteer_dev_profile-IEw0m8/SingletonLock: No such file or directory (2)
[1301414:1301414:1205/220205.443424:ERROR:chrome_main_delegate.cc(553)] Failed to create a ProcessSingleton for your profile directory. This means that running multiple instances would start multiple browser processes rather than opening a new window in the existing process. Aborting now to avoid profile corruption.`

songkeys added a commit that referenced this issue Dec 6, 2023
@songkeys
Copy link
Owner

songkeys commented Dec 6, 2023

I'm not sure about this. But I guess it's something to do with userDataDir so I pushed a fix just now. Could you try again to see if the error is still there?

@ringge
Copy link
Author

ringge commented Dec 6, 2023

thanks so much for the prompt reply, let me try the new fix

@ringge
Copy link
Author

ringge commented Dec 6, 2023

Hey, after a few times of browser reinit, puppeteer still crash

`/root/apps/translateer/node_modules/@puppeteer/browsers/lib/cjs/launch.js:271
reject(new Error([
^

Error: Failed to launch the browser process! undefined
[1309925:1309925:1206/101231.338579:ERROR:process_singleton_posix.cc(335)] Failed to create /root/apps/translateer/tmp/translateer-data/SingletonLock: File exists (17)
[1309925:1309925:1206/101231.339856:ERROR:chrome_main_delegate.cc(553)] Failed to create a ProcessSingleton for your profile directory. This means that running multiple instances would start multiple browser processes rather than opening a new window in the existing process. Aborting now to avoid profile corruption.
[1206/101231.351579:ERROR:nacl_helper_linux.cc(354)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly`

@songkeys
Copy link
Owner

songkeys commented Dec 6, 2023

May I ask:

  • What platform are you running on?
  • "After a few attempts of browser reinit" - could you please describe more clearly? Did you restart the process multiple times?
  • "After some time, the app crashed and displayed the following error" - Did this error occur when you started it or after running it for a while?

@songkeys
Copy link
Owner

songkeys commented Dec 6, 2023

Here is another issue related: puppeteer/puppeteer#10517

I guess it's a problem with the new introduced headless: true option from pupetter. As an attempt, you could try change this line:

https://github.com/Songkeys/Translateer/blob/7662b987a2a58d64e8a2bdf4533425a860165213/src/browser/pagepool.ts#L48

to:

headless: true,

and rebuild with npm run build then restart to see if it works.

@ringge
Copy link
Author

ringge commented Dec 6, 2023

May I ask:

* What platform are you running on?

* "After a few attempts of browser reinit" - could you please describe more clearly? Did you restart the process multiple times?

* "After some time, the app crashed and displayed the following error" - Did this error occur when you started it or after running it for a while?
  1. I'm running on Ubuntu LTS 22.04.3
  2. To clarify, this refer to the _resetInterval function in papepool.ts, where I saw it called initBrowser and initPages every 1 hour. So when I first run the app, everything runs ok, but after a few hours, where the initBrowser and initPages have run a few times, the error occurred
  3. As explained in 2

@ringge
Copy link
Author

ringge commented Dec 6, 2023

Here is another issue related: puppeteer/puppeteer#10517

I guess it's a problem with the new introduced headless: true option from pupetter. As an attempt, you could try change this line:

https://github.com/Songkeys/Translateer/blob/7662b987a2a58d64e8a2bdf4533425a860165213/src/browser/pagepool.ts#L48

to:

headless: true,

and rebuild with npm run build then restart to see if it works.

let me try this now, thanks

songkeys added a commit that referenced this issue Dec 6, 2023
@songkeys
Copy link
Owner

songkeys commented Dec 6, 2023

To clarify, this refer to the _resetInterval function in papepool.ts, where I saw it called initBrowser and initPages every 1 hour. So when I first run the app, everything runs ok, but after a few hours, where the initBrowser and initPages have run a few times, the error occurred

This function did have a flaw. I just pushed a commit. Could you try again?

Specifically, it might due to the reiniting happens before the old browsers compleletly closing.

@ringge
Copy link
Author

ringge commented Dec 6, 2023

To clarify, this refer to the _resetInterval function in papepool.ts, where I saw it called initBrowser and initPages every 1 hour. So when I first run the app, everything runs ok, but after a few hours, where the initBrowser and initPages have run a few times, the error occurred

This function did have a flaw. I just pushed a commit. Could you try again?

Specifically, it might due to the reiniting happens before the old browsers compleletly closing.

Great, trying now, will update how it goes

@songkeys
Copy link
Owner

songkeys commented Dec 6, 2023

You could shorten the reiniting time to test :)

@ringge
Copy link
Author

ringge commented Dec 6, 2023

You could shorten the reiniting time to test :)

Oh yes, silly me :)

@ringge
Copy link
Author

ringge commented Dec 6, 2023

I reduced the reiniting time and tested so it looks good now
Only thing is when I run api request during the browser reinitiation, sometimes I get 500 response like this, it doesn't crash the app, so it should be fine, but anyway just wanted to report back.
Thanks so much

"res":{"statusCode":500},"err":{"type":"TargetCloseError","message":"Target closed","stack":"TargetCloseError: Target closed\n at /root/apps/translateer/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Page.js:192:51\n at /root/apps/translateer/node_modules/puppeteer-core/lib/cjs/third_party/mitt/mitt.js:1:732\n at Array.map ()\n at Object.emit (/root/apps/translateer/node_modules/puppeteer-core/lib/cjs/third_party/mitt/mitt.js:1:716)\n at CdpCDPSession.emit (/root/apps/translateer/node_modules/puppeteer-core/lib/cjs/puppeteer/common/EventEmitter.js:91:23)\n at CdpCDPSession._onClosed (/root/apps/translateer/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/CDPSession.js:115:14)\n at Connection.onMessage (/root/apps/translateer/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Connection.js:132:25)\n at WebSocket. (/root/apps/translateer/node_modules/puppeteer-core/lib/cjs/puppeteer/node/NodeWebSocketTransport.js:52:32)\n at callListener (/root/apps/translateer/node_modules/ws/lib/event-target.js:290:14)\n at WebSocket.onMessage (/root/apps/translateer/node_modules/ws/lib/event-target.js:209:9)","name":"TargetCloseError"},"msg":"Target closed"}

@songkeys
Copy link
Owner

songkeys commented Dec 6, 2023

Glad to know it solves the issue.

Only thing is when I run api request during the browser reinitiation, sometimes I get 500 response like this

Because in that period, the browser is restarting so can't reach to the web page. We have to do the restarting approach because of a memory leak issue reported a while ago.

I'll see if I could improve it a little bit later.

@therealsamsquanch
Copy link

My proposal:

  1. add a global variable "_busy"
  2. before actually restarting, set _busy to TRUE and wait 10 seconds to let current translations to finish
  3. when the API receives new translation requests, before proceeding, it checks if _busy === TRUE. If it is, return an HTTP 503

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

3 participants