fix(render): isolate Chrome --user-data-dir per worker (fixes #54)#65
Open
dex0shubham wants to merge 1 commit into
Open
fix(render): isolate Chrome --user-data-dir per worker (fixes #54)#65dex0shubham wants to merge 1 commit into
dex0shubham wants to merge 1 commit into
Conversation
…il-org#54) Both CDP backends launched Chrome with --remote-debugging-port but no --user-data-dir. On a machine that already has Chrome open (normal on a desktop), the new invocation forwards to the running instance on the default profile instead of starting its own headless renderer: the CDP endpoint comes up and trivial Runtime.evaluate works, but Page.navigate never commits and Page.captureScreenshot hangs forever — every URL fails with done=0 after a ~180s timeout. This is the second of the two root causes in StarTrail-org#54 (the first, picking a non-page CDP target, was fixed in StarTrail-org#56). It's masked on Linux/CI because the bundled headless_shell launches fresh with no competing instance. Give each worker an isolated, throwaway profile via tempfile.mkdtemp, pass it as --user-data-dir, and remove it on teardown (including the connect-failure path in the turbo backend). A unique profile per worker also prevents parallel workers from colliding on one profile. Also document cross-platform Chrome resolution in the README (headless_shell is linux-x64 only; Windows/macOS use auto-detected system Chrome or CHROME_PATH). Verified on Windows 11 with system Chrome 149: pixelshot https://example.com now returns done=1 failed=0 with a valid tile (was a ~180s failure); temp profiles are cleaned up; existing render/chrome tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@dex0shubham is attempting to deploy a commit to the andylizf's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Problem
pixelshothangs and fails on Windows/macOS when the configured Chrome is a normalsystem install and the user already has Chrome open (the common desktop case). Every
URL fails with
done=0 failed=1after a ~180s hang (anasyncio.TimeoutErroronws.recv()):This is the second of the two root causes described in #54. The first —
_connect_cdpselecting a non-page CDP target — was already fixed in #56. This PR fixes the second.
Root cause
Both CDP backends launch Chrome with
--remote-debugging-portbut no--user-data-dir:render/src/pixelrag_render/backends/cdp.py—_worker(standard path)render/src/pixelrag_render/backends/fast_cdp.py—_launch_chrome(turbo path)Without an explicit profile dir, a new
chrome --remote-debugging-port=…invocationforwards to an already-running Chrome instance on the default profile instead of
starting its own headless renderer. The CDP endpoint comes up and trivial
Runtime.evaluateworks, butPage.navigatenever commits andPage.captureScreenshothangs forever.
It's masked on Linux/CI because the bundled
headless_shelllaunches fresh with nocompeting instance, so the default profile is never contended.
Fix
Give each worker an isolated, throwaway profile via
tempfile.mkdtemp, pass it as--user-data-dir, and remove it on teardown (including the connect-failure path in theturbo backend). A unique profile per worker also prevents parallel workers from colliding
on a single profile.
Also documents cross-platform Chrome resolution in the README: the bundled turbo
headless_shellauto-installs on linux-x64 only; Windows/macOS use auto-detectedsystem Chrome/Chromium (or
CHROME_PATH).Verification
On Windows 11 with system Chrome 149 (
CHROME_PATHset):pixelshot https://example.com→done=0 failed=1after ~180s.done=1 failed=0, validtile_0000.jpgproduced; temp profile dirs are createdper worker and cleaned up afterward (no leftovers under the temp dir).
ruff check/ruff format --check: clean.tests/test_render.py,tests/test_chrome_paths.py).Risk
Low. Adding
--user-data-diris a no-op on a freshly-launched Chrome (Linux/CI) and isthe standard way to isolate Chrome instances; it only changes behavior in exactly the
contended-profile case the bug describes. Teardown uses
rmtree(..., ignore_errors=True)so a still-locked profile dir never raises.
Closes #54.
🤖 Generated with Claude Code