Skip to content

Job: output is read without blocking on Windows with PHP < 8.5, so tests run in parallel and the time limit works - #471

Open
TonnyJe wants to merge 1 commit into
nette:masterfrom
TonnyJe:windows-fstat-pipes
Open

TonnyJe wants to merge 1 commit into
nette:masterfrom
TonnyJe:windows-fstat-pipes

Conversation

@TonnyJe

@TonnyJe TonnyJe commented Nov 26, 2026

Copy link
Copy Markdown
  • bug fix
  • BC break? no

On Windows with PHP < 8.5, reading an empty pipe blocks. A running test therefore blocks the others until it writes something or ends, and the time limit (--timeout, @timeout) is not enforced.

fstat() of the pipe returns the number of bytes waiting in it without blocking, so Job reads only those, at most 64 KB per check. Nothing changes on other platforms and on PHP 8.5+.

fstat() calls GetFileInformationByHandle(), which Microsoft does not document for pipes. So pipe-probe.php checks the behaviour once, in its own process with a 5 s limit, before the first test starts (the probe does not count towards that test). If it fails, Job reads as before. If fstat() fails later, that test and the tests started after it are read as before, without the time limit; tests already running keep reading without blocking. It costs about 0.1 s and two processes once per run.

PHP 8.1.34, Windows 11, -j 8, median of 10 runs:

before after
60 tests of 5–1500 ms 12.6 s 3.9 s
8 tests, 4 MB of output each 7.3 s 0.32 s
8 tests, 2 MB to stdout and 2 MB to stderr 30.0 s 0.34 s
8 tests sleeping 3 s 3.09 s 3.16 s
3 endlessly writing tests with a 1 s limit limit not enforced ends after 1.13 s

The "before" and "after" columns were measured in separate series on the same machine. Large output depends on the timer resolution: with a 1 ms timer, 8 × 4 MB takes 0.68 s before and 0.31 s after. -j 1 without a time limit is not changed.

Known limits:

  • The undocumented call. I verified it on Windows 11 and Windows Server 2022 (PHP 8.1–8.4, NTS and ZTS), not on Windows 10 or Server 2025.
  • If fstat() kept reporting fewer bytes than are in the pipe, the probe would not notice it, and a test writing a lot would wait in its write until its time limit.
  • A test that writes endlessly is read faster, so it takes more memory until its time limit (283 MB instead of 27 MB for 3 such tests and a 1 s limit). There is no limit of output before or after this change.
  • With a test writing endlessly, the runner uses most of one CPU core until its limit, because it reads the pipe continuously without sleeping while data keeps coming.
  • Not changed here, but found by the new test: on Linux and macOS (and on Windows with PHP 8.5+) one check reads all output a test keeps writing. In the CI of my fork, on ubuntu-latest with PHP 8.2, this once delayed the end of another test with a 4 s limit to 10.2 s; locally one such check took 0.3–0.6 s. So Runner.pipes.phpt runs only on Windows with PHP < 8.5.

Tests: the new ones pass on Windows 11 with PHP 8.1–8.6, NTS and ZTS; with a probe that fails, the tests that need it are skipped and the others pass. They take about 8 s on Windows < 8.5 and 25 s on 8.5+, where they test the existing code (Job.output.phpt is slow there because of php/php-src#25763). PHPStan fails as on master (DomQuery).

This PR and #470 change neighbouring lines of Job.php, so the one merged second will need a rebase.

…sts run in parallel and the time limit works

Reading an empty pipe blocks on Windows before PHP 8.5, so a running test
blocks the others and its time limit is not enforced. fstat() of the pipe tells
how many bytes wait in it, so only those are read, at most 64 KB at once.

fstat() calls GetFileInformationByHandle(), which is not documented for pipes.
pipe-probe.php verifies the behaviour once in its own process before the first
test. If it fails, or fstat() fails later, the output is read as before.
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