[php-src] PR #21873: Fix GH-20864: stabilize bug69442.phpt PTY read race

From: Date: Sat, 25 Apr 2026 16:38:09 +0000
Subject: [php-src] PR #21873: Fix GH-20864: stabilize bug69442.phpt PTY read race
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-35893@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/21873 Author: mvanhorn ## Summary Replace the two-call read_from_pipe() pattern in ext/standard/tests/file/bug69442.phpt with a non-blocking stream_select loop. The previous version raced against the child's first write and intermittently produced string(0) "" for pipe 0 instead of string(5) "foo\n". ## Why The current helper does two non-blocking-ish fread calls and concatenates them: ```php $result = fread($pipe, 1000); $again = @fread($pipe, 1000); ``` If the child hasn't flushed by the time both reads happen, the helper returns empty data and the test fails the string(5) "foo\n" expectation. The --FLAKY-- marker hides this in CI by retrying, but the race is still there. GH-20864 reports this on macOS and PPC64. ## Approach Drain the pipe with stream_select until EOF or a 10-second wall-clock cap. Set the pipe to non-blocking up front so a stuck fread can't block the test runner. Pattern matches ext/standard/tests/file/bug60120.phpt, which uses stream_set_blocking($pipe, false) plus stream_select for the same class of pipe-read race. ```php function read_from_pipe($pipe) { stream_set_blocking($pipe, false); $result = ''; $deadline = microtime(true) + 10.0; while (microtime(true) < $deadline) { $r = [$pipe]; $w = $e = null; if (@stream_select($r, $w, $e, 1) > 0) { $chunk = fread($pipe, 1000); if ($chunk !== false && $chunk !== '') { $result .= $chunk; } } if (feof($pipe)) { break; } } return $result; } ``` --FLAKY-- is left in place for one CI cycle; if the test stays green across the matrix it can be removed in a follow-up. ## Testing Test-only change. CI runs bug69442.phpt on Linux, macOS, and Windows (where supported). Local PHP build was not available on the contribution host, so verification falls to CI; the changed --FILE-- block lints clean against system PHP 8.5.5 (php -l). Closes GH-20864 > This contribution was developed with AI assistance.

« previous php.git-pulls (#35893) next »