fix: clean up Playwright process on browser startup failure - #2165
Closed
Battleplus wants to merge 2 commits into
Closed
fix: clean up Playwright process on browser startup failure#2165Battleplus wants to merge 2 commits into
Battleplus wants to merge 2 commits into
Conversation
Resolves unclecode#2155 When Playwright starts successfully but Chromium launch fails (e.g. missing browser binary, sandbox issues), the Playwright driver subprocess was leaked because no cleanup ran on the exception path. Each failed attempt left one live `node cli.js run-driver` child process, growing the process count linearly with retries. Changes: - browser_manager.py: Extract browser launch into `_launch_browser()`, wrap call in `start()` with try/except that stops Playwright on failure - async_webcrawler.py: Wrap `crawler_strategy.__aenter__()` in `start()` with try/except that calls `__aexit__()` on failure Both layers ensure partial resources are cleaned up before the exception propagates to the caller.
Signed-off-by: Battleplus <battleplus@users.noreply.github.com>
Author
|
Follow-up audit: startup rollback now catches BaseException, not only Exception, so task cancellation during Playwright/browser startup cannot leak the driver. Added unit coverage for ordinary launch failure, asyncio cancellation at BrowserManager startup, and cancellation while entering AsyncWebCrawler. Validation: 3 passed. Commit: 15a14c9. |
Author
|
Closing as a duplicate after the full audit. Earlier PR #2160 wraps the complete BrowserManager startup sequence in BaseException-safe rollback and includes a real Playwright child-process leak regression. This PR was additionally hardened for cancellation and its unit tests passed, but #2160 is earlier and covers more startup branches, so review should stay there. |
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.
这次改了什么
When Playwright starts successfully but Chromium launch fails (e.g. missing browser binary, sandbox issues), the
node cli.js run-driversubprocess was leaked. Each failed attempt left one live child process, growing the process count linearly with retries.Changes:
browser_manager.py: Extract browser launch logic into_launch_browser(), wrap the call instart()withtry/exceptthat callsself.playwright.stop()on failure.async_webcrawler.py: Wrapcrawler_strategy.__aenter__()instart()withtry/exceptthat calls__aexit__()on failure.Both layers ensure partial resources are cleaned up before the exception propagates.
怎么验证的
AsyncWebCrawler.__aenter__()now properly cleans up when browser launch fails风险
Low. Only adds cleanup on the exception path. Happy path is unchanged.
Closes #2155