Skip to content

Stop the Playwright server process, not its shell - #304

Open
razorxan wants to merge 1 commit into
pestphp:5.xfrom
razorxan:fix/stop-playwright-server-process
Open

razorxan wants to merge 1 commit into
pestphp:5.xfrom
razorxan:fix/stop-playwright-server-process

Conversation

@razorxan

@razorxan razorxan commented Nov 3, 2026

Copy link
Copy Markdown

Problem

ServerManager starts the Playwright server with Process::fromShellCommandline('./node_modules/.bin/playwright run-server …'). Symfony Process runs a string command through /bin/sh -c. When /bin/sh is dash (Debian, Ubuntu, the official PHP Docker images), the shell does not exec the command, so the process tree is:

php → sh -c ./node_modules/.bin/playwright run-server … → node ./node_modules/.bin/playwright run-server …

PlaywrightNpmServer::stop() terminates the process it knows about, which is the shell. node keeps running, reparented to PID 1. Every run that includes browser tests leaves one Playwright server behind, about 100 MB each. In a long-lived dev container they pile up until the container runs out of memory (we had 72).

Fix

Prefix the command with exec on non-Windows systems. The shell then replaces itself with node, and stop() reaches the server. Windows is unchanged, since exec is not a cmd builtin.

Reproduction

Start and stop the server the way the plugin does:

$p = Process::fromShellCommandline($prefix.'./node_modules/.bin/playwright run-server --host 127.0.0.1 --port 59999 --mode launchServer');
$p->setTimeout(0); $p->start();
$p->waitUntil(fn ($t, $o) => str_contains($o, 'Listening on'));
$p->stop(timeout: 0.1);
// count `node … --port 59999` processes
"" -> node alive after stop: 1
"exec " -> node alive after stop: 0

Running a browser test file in a php:8.5 based container leaves one orphan per run before this change and none after it.

🤖 Generated with Claude Code

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.

1 participant