Skip to content

Fix concurrent capture worker rebuild after a reaped browser#309

Merged
probably-jaden merged 1 commit into
mainfrom
fix/capture-worker-rebuild-loop-state
Jul 6, 2026
Merged

Fix concurrent capture worker rebuild after a reaped browser#309
probably-jaden merged 1 commit into
mainfrom
fix/capture-worker-rebuild-loop-state

Conversation

@probably-jaden

@probably-jaden probably-jaden commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Fixes a crash that killed entire capture runs: when the stall supervisor kills a hung browser, the dead Playwright instance leaves its event loop marked as running on that worker thread, so the replacement browser refuses to start. The fix resets the thread's loop state before rebuilding. Includes regression tests for the rebuild path.

When the supervisor kills a stalled browser, the worker's rebuild
(sync_playwright().start() via the fetcher factory) raised "Playwright
Sync API inside the asyncio loop" and killed the whole run: the dead
instance's event loop stays registered as running on the worker thread,
and _close_quietly can't clear it because Playwright teardown is
thread-affine.

- pipeline: reset the worker thread's running-loop marker to its
  pre-fetcher baseline before rebuilding (and at worker teardown),
  abandoning the poisoned loop instead of touching thread-affine
  Playwright internals.
- pipeline: a failed rebuild no longer propagates out of the worker;
  the URL keeps its error outcome and the next URL retries the rebuild.
- playwright_fetcher: __exit__ still calls playwright.stop() when
  browser.close() fails on an already-dead browser, so same-thread
  teardown un-registers the loop properly.
- tests: fake sync-Playwright-alike fetcher reproducing the poisoned
  thread state; both new tests fail on the previous code.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@probably-jaden probably-jaden merged commit 394a633 into main Jul 6, 2026
2 checks passed
@probably-jaden probably-jaden deleted the fix/capture-worker-rebuild-loop-state branch July 6, 2026 13:08
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