From dbd7c08db489dc724a846cb357bfa69efad47c46 Mon Sep 17 00:00:00 2001 From: Battleplus <3559424769@qq.com> Date: Mon, 24 Aug 2026 13:15:34 +0800 Subject: [PATCH] fix(crawler): clean up Playwright driver on __aenter__ failure (#2155) When browser launch fails inside __aenter__, the exception propagated without closing the partially-initialized crawler, leaking a live 'node run-driver' child process. Each failed attempt grew the process count linearly. Add try/except in __aenter__ to call close() on failure before re-raising. Closes #2155 --- crawl4ai/async_webcrawler.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crawl4ai/async_webcrawler.py b/crawl4ai/async_webcrawler.py index 8216d19bc..8b61b46e4 100644 --- a/crawl4ai/async_webcrawler.py +++ b/crawl4ai/async_webcrawler.py @@ -197,7 +197,17 @@ async def close(self): await self.crawler_strategy.__aexit__(None, None, None) async def __aenter__(self): - return await self.start() + try: + return await self.start() + except Exception: + # Ensure partially-initialised Playwright driver is cleaned up + # when browser launch fails inside __aenter__. Without this, + # each failed attempt leaks a live `node run-driver` child. (#2155) + try: + await self.close() + except Exception: + pass + raise async def __aexit__(self, exc_type, exc_val, exc_tb): await self.close()