Skip to content

run-tests: Fix getting stuck when the test process dies uncleanly #16456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: PHP-8.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/apt-x32/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ runs:
libxslt1-dev:i386 \
libzip-dev:i386 \
locales \
lsof \
make \
pkg-config:i386 \
re2c \
Expand Down
1 change: 1 addition & 0 deletions .github/actions/apt-x64/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ runs:
locales \
ldap-utils \
openssl \
lsof \
slapd \
language-pack-de \
libgmp-dev \
Expand Down
2 changes: 1 addition & 1 deletion ext/openssl/tests/stream_server_reneg_limit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ openssl
--SKIPIF--
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
exec('openssl help', $out, $code);
exec('openssl help 2> /dev/null', $out, $code);
if ($code > 0) die("skip couldn't locate openssl binary");
if(substr(PHP_OS, 0, 3) == 'WIN') {
die('skip not suitable for Windows');
Expand Down
2 changes: 1 addition & 1 deletion ext/phar/tests/tar/bug70417.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ zlib
--SKIPIF--
<?php

exec('lsof -p ' . getmypid(), $out, $status);
exec('lsof -p ' . getmypid() . ' 2> /dev/null', $out, $status);
if ($status !== 0) {
die("skip lsof(8) not available");
}
Expand Down
14 changes: 7 additions & 7 deletions ext/snmp/snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,13 @@ PHP_MINIT_FUNCTION(snmp)
{
netsnmp_log_handler *logh;

/* Disable logging, use exit status'es and related variabled to detect errors */
shutdown_snmp_logging();
logh = netsnmp_register_loghandler(NETSNMP_LOGHANDLER_NONE, LOG_ERR);
if (logh) {
logh->pri_max = LOG_ERR;
}

init_snmp("snmpapp");
/* net-snmp corrupts the CTYPE locale during initialization. */
zend_reset_lc_ctype_locale();
Expand All @@ -2006,13 +2013,6 @@ PHP_MINIT_FUNCTION(snmp)
netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PERSIST_STATE, 1);
#endif

/* Disable logging, use exit status'es and related variabled to detect errors */
shutdown_snmp_logging();
logh = netsnmp_register_loghandler(NETSNMP_LOGHANDLER_NONE, LOG_ERR);
if (logh) {
logh->pri_max = LOG_ERR;
}

memcpy(&php_snmp_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
php_snmp_object_handlers.read_property = php_snmp_read_property;
php_snmp_object_handlers.write_property = php_snmp_write_property;
Expand Down
2 changes: 0 additions & 2 deletions ext/snmp/tests/bug64159.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ var_dump(("ab8283f948419b2d24d22f44a80b17d3" === md5(snmpget($hostname, $communi

?>
--EXPECTF--
MIB search path: %s
Cannot find module (noneXistent): At line %d in (%s)
bool(true)
2 changes: 1 addition & 1 deletion ext/standard/tests/file/bug81145.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (disk_free_space(__DIR__) < 0x220000000) die("skip insuffient disk space");
if (PHP_OS_FAMILY !== "Windows") {
$src = __DIR__ . "/bug81145_src.bin";
define('SIZE_4G', 0x100000000);
exec("fallocate -l " . (SIZE_4G-0x100) . " " . escapeshellarg($src), $output, $status);
exec("fallocate -l " . (SIZE_4G-0x100) . " " . escapeshellarg($src) . " 2> /dev/null", $output, $status);
if ($status !== 0) die("skip fallocate() not supported");
@unlink(__DIR__ . "/bug81145_src.bin");
}
Expand Down
16 changes: 16 additions & 0 deletions ext/zend_test/tests/run-tests_stuck_when_subprocess_exists.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
run-tests: Does not get stuck when a test spawns a subprocess and dies uncleanly.
--EXTENSIONS--
posix
--FILE--
<?php

$handle = popen("sleep 5; echo not visible", "r");

fwrite(STDERR, "foo\n");
posix_kill(posix_getpid(), 9);

?>
--EXPECTF--
foo%A
Termsig=9
14 changes: 5 additions & 9 deletions run-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ function system_with_timeout(
$timeout *= 3;
}

while (true) {
do {
/* hide errors from interrupted syscalls */
$r = $pipes;
$w = null;
Expand All @@ -1225,24 +1225,20 @@ function system_with_timeout(
/* timed out */
$data .= "\n ** ERROR: process timed out **\n";
proc_terminate($proc, 9);
return $data;
break;
}

if ($n > 0) {
if ($captureStdOut) {
if ($captureStdOut && in_array($pipes[1], $r)) {
$line = fread($pipes[1], 8192);
} elseif ($captureStdErr) {
} elseif ($captureStdErr && in_array($pipes[2], $r)) {
$line = fread($pipes[2], 8192);
} else {
$line = '';
}
if (strlen($line) == 0) {
/* EOF */
break;
}
$data .= $line;
}
}
} while (!feof($pipes[1]) || !feof($pipes[2]));

$stat = proc_get_status($proc);

Expand Down
Loading