Shut down the Node bridge when its parent dies#118
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
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.