Skip to content

Commit

Permalink
Do not wait when the child process does not exist (#3832)
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf authored Nov 11, 2020
1 parent 3c08c9a commit 72a5be9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
38 changes: 38 additions & 0 deletions tests/swoole_runtime/proc/close_after_wait.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--
swoole_runtime/proc: proc_close() after wait
--SKIPIF--
<?php require __DIR__ . '/../../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../../include/bootstrap.php';

include_once dirname(__FILE__) . "/proc_open_pipes.inc";
Swoole\Runtime::enableCoroutine();

Co\run(function() {
$descriptorspec = array(
0 => array("pipe", "/dev/null"),
1 => array("pipe", "/dev/null"),
2 => array("pipe", "/dev/null")
);

$proc = proc_open('/bin/sleep 30', $descriptorspec, $pipes);
Assert::notEmpty($proc);
echo "wait begin\n";

go(function() use($proc) {
usleep(100000);
proc_terminate($proc);
});

$info = Co\System::wait();
Assert::notEmpty($info);
echo "wait end\n";
proc_close($proc);
echo "proc_close end\n";
});
?>
--EXPECTF--
wait begin
wait end
proc_close end
7 changes: 4 additions & 3 deletions thirdparty/php/standard/proc_open.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ static void proc_co_rsrc_dtor(zend_resource *rsrc)
}
}

if (proc->running)
{
swoole_coroutine_waitpid(proc->child, &wstatus, 0);
if (proc->running) {
if (::waitpid(proc->child, &wstatus, WNOHANG) == 0) {
swoole_coroutine_waitpid(proc->child, &wstatus, 0);
}
}
if (proc->wstatus)
{
Expand Down

0 comments on commit 72a5be9

Please sign in to comment.