Skip to content

fix: stop the playwright server process, not only its shell - #281

Open
Leander-Forma wants to merge 1 commit into
pestphp:5.xfrom
Forma-nl:fix/exec-playwright-server
Open

Leander-Forma wants to merge 1 commit into
pestphp:5.xfrom
Forma-nl:fix/exec-playwright-server

Conversation

@Leander-Forma

Copy link
Copy Markdown

What

PlaywrightNpmServer::start() prefixes the command with exec (not on Windows).

Why

The server is started with Process::fromShellCommandline(). On Linux and macOS that gives this tree:

pest
└─ sh -c ./node_modules/.bin/playwright run-server --host 127.0.0.1 --port 40123 --mode launchServer
   └─ node ./node_modules/.bin/playwright run-server ...

stop() signals the sh. The sh exits, node is reparented to init (or systemd --user) and keeps listening. So every test run, also a clean one, leaves a Playwright server of ~170 MB behind. On a machine where several runs happen in a day they pile up. We found 28 of them on a shared dev VM in one morning.

A side effect: a caller that pipes Pest's output (vendor/bin/pest | tail) can hang after the run, because the leftover node still holds the pipe open.

With exec, the shell is replaced by node, so the process Symfony signals is the server itself.

Test

tests/Unit/Playwright/PlaywrightNpmServerTest.php starts the server, stops it, and asserts that nothing listens on the port anymore. It fails on the current code ("Failed asserting that true is false") and passes with the change. Skipped on Windows.

composer test:unit, phpstan, pint --test and rector --dry-run pass locally.

🤖 Generated with Claude Code

The server is started with Process::fromShellCommandline(), so on Linux and
macOS the tree is `sh -c "./node_modules/.bin/playwright run-server ..."` with
node as a child of sh. stop() signals the sh, which exits, and node keeps
running and listening, reparented to init. Every run leaves one server behind.

Prefixing the command with `exec` makes node the process that is started and
signalled. Windows runs the command through cmd and is left as it was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants