fix: give the playwright npm server time to shut down browser children - #211
fix: give the playwright npm server time to shut down browser children#211jordanmiguel wants to merge 1 commit into
Conversation
…wser children Symfony's Process::stop(0.1) sent SIGTERM and escalated to SIGKILL after 100ms. In headed mode, Chromium's graceful close typically needs ~1s; the SIGKILL interrupted mid-teardown, leaving orphan browser processes and stalled pipes. The parent pest process then hung on wait() for file handles that never closed, forcing the user to Ctrl-C. Bumps the grace period to 2.0s, which consistently clears Chromium even in headed mode on macOS/Linux. Headless mode was unaffected; headed-mode runs now exit cleanly.
|
I've got the same issue but only when i use Firefox. This PR fixed it 🎊. Thanks. |
|
I hit this same teardown hang on Firefox (headless) and can confirm this PR fixes it there too, not only Chromium in headed mode. Without the change, With Environment: pest-plugin-browser v4.3.1, Playwright 1.59.x, PHP 8.3, macOS. Would be great to get this merged. Thanks @jordanmiguel! |
The bug
When running a suite with
--headed, thepestprocess hangs indefinitely after the "Tests: N passed" summary prints. On CI / in shells with a pipe it keeps the shell prompt busy; locally the user has to hit Ctrl-C to reclaim the terminal.Repro (macOS + Linux, any project with browser tests):
./vendor/bin/pest tests/Browser --headed # Summary prints, then hangs.Headless mode is unaffected.
Root cause
In
PlaywrightNpmServer::stop():Symfony's
Process::stop($timeout)sendsSIGTERM, waits$timeoutseconds, then escalates toSIGKILL. 100ms is too short for headed Chromium — its graceful close typically takes 700–1200ms because it has to flush IPC to its GPU/renderer children, persist session state, and tear down its windows.With the old 100ms grace period the server receives
SIGKILLwhile Chromium is still in mid-shutdown; its stdin/stdout pipes stay open on orphan descriptors, so the parent PHP process blocks inproc_close/fclosewaiting on them. That is the observable hang.Fix
Bump the grace period to
2.0seconds. Plenty of headroom for headed Chromium on every platform tested (macOS 14 Apple Silicon, Ubuntu 22.04 x86_64) and still bounded so a truly stuck Playwright server still getsSIGKILL.Headless runs complete faster than the grace period, so there is no perceptible overhead —
stop()returns as soon as Node exits.Before / after
Notes
SIGKILLstill fires at T+2s — no regression vs. the current escalate-to-SIGKILL behaviour, just pushed out 1.9s.tests/CoreFeatures/HeadedShutdownTest.phpthat launches + closes + asserts the parent exits within N seconds) if that fits the project's testing philosophy.