Skip to content

fix(browsers): do not close a browser as inactive while a page opening is in flight - #2156

Open
vdusek wants to merge 1 commit into
masterfrom
fix/browser-pool-reaper-race
Open

fix(browsers): do not close a browser as inactive while a page opening is in flight#2156
vdusek wants to merge 1 commit into
masterfrom
fix/browser-pool-reaper-race

Conversation

@vdusek

@vdusek vdusek commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

The windows-latest / 3.10 unit-test job failed with TargetClosedError: BrowserContext.new_page: Target page, context or browser has been closed in test_new_page_with_each_plugin. It is not a test flake: the BrowserPool inactive-browser reapers judge a browser only by its finished pages (idle_time runs from controller construction and pages is populated only once new_page returns), so on a slow runner they gracefully close a freshly launched browser whose first new_page() is still creating its context. Any user on a loaded machine can hit the same error (related: #1660).

The fix exposes the already-tracked in-flight openings as BrowserController.is_opening_pages and guards both reapers with it, so such a browser is neither marked inactive nor closed. A new regression test reproduces the race deterministically by gating the first context.new_page() call and running one reaper cycle while the opening is pending — it fails with the exact CI error before the fix and passes after.

✍️ Drafted by Claude Code

@vdusek vdusek added t-tooling Issues with this label are in the ownership of the tooling team. adhoc Ad-hoc unplanned task added during the sprint. labels Aug 14, 2026
@vdusek vdusek self-assigned this Aug 14, 2026
@github-actions github-actions Bot added this to the 147th sprint - Tooling team milestone Aug 14, 2026
@github-actions github-actions Bot added the tested Temporary label used only programatically for some analytics. label Aug 14, 2026
@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.61%. Comparing base (091410f) to head (c5def7b).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
src/crawlee/browsers/_browser_controller.py 66.66% 1 Missing ⚠️
src/crawlee/browsers/_browser_pool.py 50.00% 1 Missing ⚠️
.../crawlee/browsers/_stagehand_browser_controller.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2156      +/-   ##
==========================================
+ Coverage   93.51%   93.61%   +0.10%     
==========================================
  Files         181      181              
  Lines       12653    12664      +11     
==========================================
+ Hits        11832    11855      +23     
+ Misses        821      809      -12     
Flag Coverage Δ
unit 93.61% <76.92%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vdusek
vdusek requested review from Mantisus and Pijukatel August 14, 2026 10:05
@vdusek
vdusek marked this pull request as ready for review August 14, 2026 10:05

@Mantisus Mantisus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants