Skip to content

Shut down the Node bridge when its parent dies#118

Merged
smnandre merged 2 commits into
playwright-php:mainfrom
smnandre:sa/browser-leak
Jul 21, 2026
Merged

Shut down the Node bridge when its parent dies#118
smnandre merged 2 commits into
playwright-php:mainfrom
smnandre:sa/browser-leak

Conversation

@smnandre

Copy link
Copy Markdown
Member

Killing a PHP process with SIGTERM or SIGKILL left the Node bridge and its browsers running forever.

No PHP shutdown function runs, and the bridge had no handler for its stdin closing. Interrupted runs (CI timeouts, IDE stop buttons, ...) piled up headless browsers.

The bridge now exits when stdin ends or closes.

smnandre added 2 commits July 21, 2026 16:50
A PHP process killed with SIGTERM or SIGKILL never runs its shutdown
functions, so nothing terminates the bridge. Its stdin closes, but the
server registered no lifecycle handler and kept waiting on input that
would never come, holding every browser it had open. Chromium is a child
of the bridge rather than of PHP, so it was reparented to init and no
PHP-side cleanup could reach it. Observed outcome: 175 headless browsers
alive for up to three days, and the macOS code-signing clones pinned by
them filling the disk.

Exit on stdin end or close, which is the one signal available in every
case a PHP shutdown hook cannot cover, and on SIGTERM and SIGHUP. Guard
against re-entry and arm an unref'd watchdog so a browser that refuses to
close cannot wedge the process: exiting without cleanup still lets
Chromium see the broken pipe, hanging does not.

The regression test kills a probe process outright and asserts that the
bridge and browser pids it captured beforehand are gone. It watches
captured pids rather than a pgrep count, since any machine already
running Playwright would break a count, and compares command lines rather
than bare pid existence, since a recycled pid would otherwise read as a
survivor. Reading parentage and force-killing differ per platform, so
each variant is gated with RequiresOperatingSystemFamily.
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@smnandre
smnandre merged commit ca6ad4d into playwright-php:main Jul 21, 2026
11 checks passed
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