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]: "Waiting for target frame x failed" when crawling a lot of websites concurrently #8832

Closed
stevenwdv opened this issue Aug 23, 2022 · 9 comments · Fixed by #8835, #8828 or #8895
Closed
Assignees

Comments

@stevenwdv
Copy link

stevenwdv commented Aug 23, 2022

Bug description

Steps to reproduce the problem:

  1. Do a lot at the same time (opening a lot of browsers and visiting pages etc.), causing Node to lag.
  2. Observe an unhandledRejection like the following:
TimeoutError: Waiting for target frame 38DAB13DFEC9AD09315770D838D9F8C9 failed
    at Timeout._onTimeout (path\to\my_package\node_modules\puppeteer\src\util\DeferredPromise.ts:36:14)
    at listOnTimeout (node:internal/timers:564:17)
    at processTimers (node:internal/timers:507:7)

This is caused by the promise from FrameManager.ts:153 not being fulfilled within 5 seconds (hardcoded in DeferredPromise.ts). If you add if (isRejected) console.log('resolved anyway') to resolve: in DeferredPromise.ts and set process.on('uncaughtException', console.error) then you can see that the promise will be resolved anyway later on.

I think the timeout should probably be configurable in some way (or removed entirely, but it probably serves a purpose).

Puppeteer version

16.2.0

Node.js version

18.7.0

npm version

8.17.0

What operating system are you seeing the problem on?

Windows

Relevant log output

No response

@stevenwdv stevenwdv added the bug label Aug 23, 2022
@OrKoN OrKoN self-assigned this Aug 23, 2022
OrKoN added a commit that referenced this issue Aug 24, 2022
Issue #8832 makes a good point that we should not be making
implicit assumptions about the client's performance
when waiting for internal events. At the same time,
we want to be able to get the debug info if some promises
never resolve because of missing backend events.

This PR adds a variable to turn on timeouts for deferred
promises created using `createDebuggableDeferredPromise`.
We can use it in our tests to catch never-resolving
promises or when reproducing bug reports where Puppeteer
hangs indefinitely.

Closes #8832
@stevenwdv
Copy link
Author

stevenwdv commented Aug 24, 2022

Update: I sometimes have this issue even when I change the timeout to 30 seconds while doing just 5 crawls concurrently, and I can see that the promise would actually be fulfilled eventually.

@ivibe
Copy link

ivibe commented Aug 24, 2022

The worst part - there is no way to catch this error. If it happens node crashes.

OrKoN added a commit that referenced this issue Aug 24, 2022
Issue #8832 makes a good point that we should not be making
implicit assumptions about the client's performance
when waiting for internal events. At the same time,
we want to be able to get the debug info if some promises
never resolve because of missing backend events.

This PR adds a variable to turn on timeouts for deferred
promises created using `createDebuggableDeferredPromise`.
We can use it in our tests to catch never-resolving
promises or when reproducing bug reports where Puppeteer
hangs indefinitely.

Closes #8832
@stevenwdv
Copy link
Author

stevenwdv commented Aug 24, 2022

@ivibe Except process.on('uncaughtException', console.error) that is, but yeah that's a bit evil.
--unhandled-rejections=warn may also work

@ivibe
Copy link

ivibe commented Aug 24, 2022

@stevenwdv yep, there're workarounds, but I meant traditional try ... catch block :)

stevenwdv added a commit to stevenwdv/tracker-radar-collector that referenced this issue Sep 1, 2022
@stevenwdv
Copy link
Author

stevenwdv commented Sep 2, 2022

@OrKoN I just checked and unfortunately the issue is not fixed in puppeteer 17.1.0. This seems to be a regression compared to 17.0.0. I can reproduce it with the snippet from #8838.

TimeoutError: Waiting for target frame 94B6342A551DB27D1F1D5A185A000C34 failed
    at Timeout._onTimeout (file:///C:/dev/puppeteer-test/node_modules/puppeteer/lib/esm/puppeteer/util/DeferredPromise.js:26:22)
    at listOnTimeout (node:internal/timers:564:17)
    at process.processTimers (node:internal/timers:507:7)

Can this issue be reopened?

@OrKoN OrKoN reopened this Sep 2, 2022
@OrKoN
Copy link
Collaborator

OrKoN commented Sep 2, 2022

Sorry, looks like a regression slipped in the @jrandolf's refactoring #8863

@NoelToy
Copy link

NoelToy commented Mar 14, 2024

Hi there am using puppeteer version 17.1.0 and Node 18.10.0. Am facing the exact same issue when I am doing a web scrapping concurrently. Is there any fix or workaround for this? It would be so helpful if it can be address as we are facing the issue in a production system.

@stevenwdv
Copy link
Author

@NoelToy
Workaround: Reduce concurrency, only scrape a couple of sites in parallel.
Fix: Already released, just upgrade puppeteer to v17.1.1 or higher, you're on a really old version.

@NoelToy
Copy link

NoelToy commented Mar 14, 2024

Thanks, I have already changed the version to 17.1.1 and the issue got resolved. Thanks once again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment