fix: Fix memory leak in `PlaywrightCrawler` on browser context creation by Pijukatel · Pull Request #1446 · apify/crawlee-python

@Pijukatel

Description

  • Add Lock to PlaywrightBrowserController._browser_context creation to ensure no orphaned duplicate contexts are created.

Issues

Testing

  • Unit test added.
  • Benchmark actor with PlaywrightCrawler used to confirm normal memory consumption with this fix.

@Pijukatel Pijukatel changed the title fix: Fix memory leak in PlaywrightCrawler on context creation fix: Fix memory leak in PlaywrightCrawler on browser context creation

Oct 1, 2025

@Pijukatel

@Pijukatel

Memory consumption of PlaywrightCrawler on 2000 pages:

  • With fix: Average:378.4 MB Maximum:638.8 MB
  • Without fix: Average:2.8 GBMaximum:3.8 GB -> Gets memory starved and stops.

vdusek

Choose a reason for hiding this comment

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

Good job, thanks

@Pijukatel

Ignoring the failing test due to #1441

@B4nan

We should get this out soon, doesn't have to be right ahead, but I'd ship it this week.

@vdusek

We should get this out soon, doesn't have to be right ahead, but I'd ship it this week.

Sure, ideally together with the #1438 and #1440.