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

Bug: No way to handle UnhandledPromiseRejectionWarning inside cluster.work #502

Open
mhassan1 opened this issue Dec 9, 2022 · 5 comments

Comments

@mhassan1
Copy link

mhassan1 commented Dec 9, 2022

When the Promise returned by doWork here is rejected, we end up with an UnhandledPromiseRejectionWarning, which we can only deal with using a global process.on('unhandledRejection', ...) listener. There should be a better way for consumers to handle this error; maybe cluster should emit a clustererror event (or an error event, since it may be fatal), in this case.

I would be happy to contribute a fix, once we have an approach.

To reproduce:

const { Cluster } = require('puppeteer-cluster')

Cluster.launch({
  puppeteerOptions: {
    args: [
      '--single-process'
    ]
  },
}).then(cluster => {
  cluster.queue(async () => {})
})

NOTE: This reproduces on my Mac because the --single-process flag prevents Chromium from starting up. YMMV.

Actual output:
An UnhandledPromiseRejectionWarning is emitted by the process, and the process exits:

Error: Unable to get browser page
    at Worker.<anonymous> (/puppeteer-cluster/node_modules/puppeteer-cluster/dist/Worker.js:41:31)
    at Generator.next (<anonymous>)
    at fulfilled (/puppeteer-cluster/node_modules/puppeteer-cluster/dist/Worker.js:5:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.12.1

Process finished with exit code 1

Expected output:
An event is emitted by cluster, and no UnhandledPromiseRejectionWarning is emitted by the process

Related: #323

@drizzef
Copy link

drizzef commented Feb 6, 2023

im also facing the same issue.

@zhaow-de
Copy link

I can confirm the symptom. The roor cause seems like at

this.workCallTimeout = setTimeout(
, the SetTimeout made Cluster.doWork run in the event loop scheduled as macro tasks. Therefore, any error rejects Cluster.doWork does not populate to Cluster.work and onward, which leads to the unhandeld rejection warning.

@yangguangwuwu
Copy link

me too

@yangguangwuwu
Copy link

yangguangwuwu commented Oct 30, 2023

throw new Error('Unable to get browser page');
^

Error: Unable to get browser page
at Worker. (/data/node_modules/puppeteer-cluster/dist/Worker.js:41:31)
at Generator.next ()
at fulfilled (/data/node_modules/puppeteer-cluster/dist/Worker.js:5:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

@yangguangwuwu
Copy link

delete --single-process
run ok
It is possible that puppeteer-cluster relies on multiple processes of browser instances.

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

4 participants