[Bug]: Browser plugin — on Windows the run can hang forever before any browser starts (waitUntil() misses Playwright's "Listening on" line)

Aperta
#1,941 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 5 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php, playwright, symfony
Ambito
testing

Direzione di ricerca

Start at PlaywrightNpmServer::start() and inspect the Symfony Process waitUntil(), isRunning(), getOutput(), and getIncrementalOutput() behavior described in the report. Reproduce with tests/Browser/OneTest.php on Windows using the 20-run loop, then verify that the server-start wait cannot miss the “Listening on” line, enforces the 30-second limit, and turns a timeout into the reported error.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
What Happened

On Windows, a browser test run sometimes hangs forever before any browser starts — no output at all, not even the first test name. About 1 run in 4 on our machine. Filed here because issues are disabled on pestphp/pest-plugin-browser.

It is not #1855 or #1801: in those the websocket is connected. Here the plugin never gets that far; it is still inside PlaywrightNpmServer::start().

Cause. start() waits for the server's one Listening on line with setTimeout(0) and

$this->systemProcess->waitUntil(
    fn (string $type, string $output): bool => str_contains($output, $this->until)
);

On Windows, Symfony Process' waitUntil() calls isRunning() on every loop (Process.php, the '\\' === \DIRECTORY_SEPARATOR ? $this->isRunning() : … line; also the updateStatus(false) right at the start). isRunning() → updateStatus() → readPipes() reads new output into the buffer without calling the waitUntil callback. If the Listening on line arrives at that moment, the callback never sees it; Playwright prints nothing else, so the loop waits forever.

Evidence, captured during a hang:

  • netstat: 127.0.0.1:<port> LISTENING by the playwright … run-server node process.
  • %TEMP%\sf_proc_01.out holds 35 bytes = Listening on ws://127.0.0.1:51105/\n.
  • A trace in the plugin logged start() being entered, then nothing: the waitUntil callback was never called with any chunk (in good runs it is called once, ~0.4 s later, with the whole line).
  • Starting the same command 15 times from a plain script that polls getIncrementalOutput() never missed the line, which points at waitUntil() + isRunning() rather than Playwright.
How to Reproduce

On Windows 11, run a one-test browser file (visit('/')->assertSee('…')) in a loop, e.g. 20 × php artisan test tests/Browser/OneTest.php with a 45 s limit. A run hangs every 3–5 runs.

Suggested fix

Poll the whole buffered output (which isRunning() and getOutput() both fill) with a time limit, instead of relying on the callback:

$deadline = microtime(true) + 30;
while ($this->systemProcess->isRunning() && ! str_contains($this->systemProcess->getOutput(), $this->until)) {
    if (microtime(true) > $deadline) {
        $this->systemProcess->stop(0.1);

        throw new RuntimeException('Playwright did not start within 30 seconds.');
    }
    usleep(10_000);
}

With this change, 30 of 30 runs passed (before: a hang every 3–5 runs). A time limit here would also have turned the hang into a clear error.

Versions
  • Pest 5.2.1, pest-plugin-browser 5.0.1, symfony/process 8.1.7
  • Playwright 1.63.0 (Chromium)
  • PHP 8.4.24
  • Windows 11 Pro (10.0.26200), run from Git Bash
Lingua principale
PHP
Stelle
11.8k
Fork
559
Merge medio
5g 23h
PR unite (30g)
24

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pestphp/pest

Tutte le issue di pestphp/pest

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.