[Process] Fix infinite waiting for stopped process
This commit is contained in:
parent
9e4d5ff47d
commit
6b9ee1e1c5
@ -427,6 +427,7 @@ class Process implements \IteratorAggregate
|
|||||||
} while ($running);
|
} while ($running);
|
||||||
|
|
||||||
while ($this->isRunning()) {
|
while ($this->isRunning()) {
|
||||||
|
$this->checkTimeout();
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
36
src/Symfony/Component/Process/Tests/ErrorProcessInitiator.php
Executable file
36
src/Symfony/Component/Process/Tests/ErrorProcessInitiator.php
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Process\Tests;
|
||||||
|
|
||||||
|
use Symfony\Component\Process\Exception\ProcessTimedOutException;
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
|
require \dirname(__DIR__).'/vendor/autoload.php';
|
||||||
|
|
||||||
|
list('e' => $php) = getopt('e:') + ['e' => 'php'];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$process = new Process("exec $php -r \"echo 'ready'; trigger_error('error', E_USER_ERROR);\"");
|
||||||
|
$process->start();
|
||||||
|
$process->setTimeout(0.5);
|
||||||
|
while (false === strpos($process->getOutput(), 'ready')) {
|
||||||
|
usleep(1000);
|
||||||
|
}
|
||||||
|
$process->signal(SIGSTOP);
|
||||||
|
$process->wait();
|
||||||
|
|
||||||
|
return $process->getExitCode();
|
||||||
|
} catch (ProcessTimedOutException $t) {
|
||||||
|
echo $t->getMessage().PHP_EOL;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
@ -1551,6 +1551,15 @@ EOTXT;
|
|||||||
$this->assertSame($env, $p->getEnv());
|
$this->assertSame($env, $p->getEnv());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testWaitStoppedDeadProcess()
|
||||||
|
{
|
||||||
|
$process = $this->getProcess(self::$phpBin.' '.__DIR__.'/ErrorProcessInitiator.php -e '.self::$phpBin);
|
||||||
|
$process->start();
|
||||||
|
$process->setTimeout(2);
|
||||||
|
$process->wait();
|
||||||
|
$this->assertFalse($process->isRunning());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $commandline
|
* @param string $commandline
|
||||||
* @param string|null $cwd
|
* @param string|null $cwd
|
||||||
|
Reference in New Issue
Block a user