Repository navigation
fix(browsers): Release a page whose close never finishes - #2441
Open
PrashanthLande wants to merge 2 commits into
Open
PrashanthLande wants to merge 2 commits into
PrashanthLande wants to merge 2 commits into
Conversation
Mantisus
suggested changes
Nov 15, 2026
Mantisus
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the PR, but in its current form it introduces a breaking change. Could you update it so the timeout applies only to the page close?
| page: Any = crawlee_page.page | ||
| page.close = close_with_hooks | ||
| try: | ||
| await asyncio.wait_for(close_sequence(), timeout) |
Collaborator
There was a problem hiding this comment.
This also cancels user hooks that take longer than 5 seconds, which is a breaking change.
Contributor
Author
There was a problem hiding this comment.
Thanks @Mantisus , updated: the timeout now applies only to page.close() itself. Pre and post page close hooks run without a time limit, as before. Added test_slow_page_close_hooks_are_not_cancelled to cover it.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
PlaywrightCrawlerhangs forever when Chromium never finishes apage.close(). This happens when a page navigates itself with JavaScript (e.g.location.reload()) right as the crawler closes it.crawler.run()never returns, even when wrapped inasyncio.wait_for.BrowserPoolnow givespage.close()5 seconds. If it does not finish, it logs a warning, releases the page from its browser and retires the browser, so it gets no new pages and is closed once its remaining pages are closed.BrowserController.register_page_closed(), so the page is released even when itscloseevent never arrives. It has a no-op default, so existing custom controllers keep working.PAGE_CLOSE_TIMEOUT_MILLIS) rather thanoperation_timeout, since a healthy close takes milliseconds. Happy to make it configurable if you prefer.Issues
Crawled 3/3 pages, 0 failed requestsfor over 20 minutes, and a coroutine dump of the stuck process showed the worker task waiting onPage.closeinside the crawler's deferred cleanup.Testing
tests/integration/browsers/test_browser_pool.py:Page.closeto never finish (the real trigger, a page reloading itself during close, is timing-dependent and hard to reproduce on demand). Before the fixcrawler.run()hung forever; now it logs the warning and returns after about 6 s.Repro (simulated hang)
Checklist