Skip to content

Commit d1e2d99

Browse files
committed
bug69442.phpt: avoid feof() Notice on closed PTY slave
The previous patch read until feof() returned true, but feof() on a PTY pipe can trigger an underlying read of the default 8192-byte buffer that returns EIO once the slave side has closed. PHP surfaces that as a Notice, which appears in stdout and breaks the --EXPECT-- block on every platform with PTY support. Drop the feof() check, exit the loop as soon as stream_select reports no data within 1s (PTY EOF), and silence any EIO Notice from the trailing fread/stream_select. Also shrinks the wall-clock cap from 10s to 5s so the success path stops sitting in select for the full deadline.
1 parent 1266163 commit d1e2d99

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

ext/standard/tests/file/bug69442.phpt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,24 @@ $process = proc_open($cmd, $descriptors, $pipes);
3232

3333
function read_from_pipe($pipe) {
3434
/* The child may not have flushed by the time we read, and a PTY pipe can
35-
* return partial data across reads. Wait for data with stream_select and
36-
* loop until EOF or a generous wall-clock timeout. */
35+
* return partial data across reads. Loop until stream_select reports no
36+
* data within 1s (PTY EOF) or a 5s wall-clock deadline. Don't call
37+
* feof() on a PTY pipe: it can trigger an underlying read that returns
38+
* EIO when the slave side has closed, surfacing an unwanted Notice. */
3739
stream_set_blocking($pipe, false);
3840
$result = '';
39-
$deadline = microtime(true) + 10.0;
41+
$deadline = microtime(true) + 5.0;
4042
while (microtime(true) < $deadline) {
4143
$r = [$pipe];
4244
$w = $e = null;
43-
if (@stream_select($r, $w, $e, 1) > 0) {
44-
$chunk = fread($pipe, 1000);
45-
if ($chunk !== false && $chunk !== '') {
46-
$result .= $chunk;
47-
}
45+
if (@stream_select($r, $w, $e, 1) <= 0) {
46+
break;
4847
}
49-
if (feof($pipe)) {
48+
$chunk = @fread($pipe, 1000);
49+
if ($chunk === false || $chunk === '') {
5050
break;
5151
}
52+
$result .= $chunk;
5253
}
5354
return $result;
5455
}

0 commit comments

Comments
 (0)