Skip to content

Commit b4ace61

Browse files
committed
run-tests: Fix getting stuck when the test process dies uncleanly
When a test process spawns a subprocess that keeps STDOUT open and then dies uncleanly, while writing something to STDERR `run-tests.php` would erroneously attempt to read from `STDOUT` and then get blocked until the subprocess dies (which might never happen).
1 parent ab595c0 commit b4ace61

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
run-tests: Does not get stuck when a test spawns a subprocess and dies uncleanly.
3+
--EXTENSIONS--
4+
posix
5+
--FILE--
6+
<?php
7+
8+
$handle = popen("sleep 5; echo not visible", "r");
9+
10+
fwrite(STDERR, "foo\n");
11+
posix_kill(posix_getpid(), 9);
12+
13+
?>
14+
--EXPECTF--
15+
foo%A
16+
Termsig=9

run-tests.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,10 +1229,10 @@ function system_with_timeout(
12291229
}
12301230

12311231
if ($n > 0) {
1232-
if ($captureStdOut) {
1233-
$line = fread($pipes[1], 8192);
1234-
} elseif ($captureStdErr) {
1235-
$line = fread($pipes[2], 8192);
1232+
if ($captureStdOut && isset($r[1])) {
1233+
$line = fread($r[1], 8192);
1234+
} elseif ($captureStdErr && isset($r[2])) {
1235+
$line = fread($r[2], 8192);
12361236
} else {
12371237
$line = '';
12381238
}

0 commit comments

Comments
 (0)