Skip to content

fix: Respect max_open_pages_per_browser limit for PlaywrightBrowserController on concurrent new_page calls#1712

Open
Mantisus wants to merge 1 commit intoapify:masterfrom
Mantisus:fix-controller-race-condition
Open

fix: Respect max_open_pages_per_browser limit for PlaywrightBrowserController on concurrent new_page calls#1712
Mantisus wants to merge 1 commit intoapify:masterfrom
Mantisus:fix-controller-race-condition

Conversation

@Mantisus
Copy link
Collaborator

@Mantisus Mantisus commented Feb 4, 2026

Description

  • Respect max_open_pages_per_browser limit for PlaywrightBrowserController on concurrent new_page calls.

Testing

  • Added a test test_max_open_pages_limit_error_on_concurrent_creation to verify that concurrent calls do not create several pages exceeding the max_open_pages_per_browser limit.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request attempts to fix a concurrency issue in PlaywrightBrowserController where concurrent calls to new_page() could create more pages than allowed by the max_open_pages_per_browser limit. The fix introduces a counter to track pages currently being opened and includes this in the capacity check.

Changes:

  • Added _opening_pages_count counter to track concurrent page creation operations
  • Modified has_free_capacity property to include pages being opened in the capacity calculation
  • Restructured new_page() method with try-finally block to properly manage the opening counter
  • Added test test_max_open_pages_limit_on_concurrent_creation to verify concurrent creation respects the limit

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/crawlee/browsers/_playwright_browser_controller.py Introduces _opening_pages_count counter and modifies capacity checking logic with try-finally protection
tests/unit/browsers/test_playwright_browser_controller.py Adds test for concurrent page creation with max limit of 1

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Successfully merging this pull request may close these issues.

1 participant