From 6b9ee1e1c569f61d1a871671c9e2d1cdffea217b Mon Sep 17 00:00:00 2001 From: mshavliuk Date: Wed, 22 May 2019 02:21:35 +0300 Subject: [PATCH] [Process] Fix infinite waiting for stopped process --- src/Symfony/Component/Process/Process.php | 1 + .../Process/Tests/ErrorProcessInitiator.php | 36 +++++++++++++++++++ .../Component/Process/Tests/ProcessTest.php | 9 +++++ 3 files changed, 46 insertions(+) create mode 100755 src/Symfony/Component/Process/Tests/ErrorProcessInitiator.php diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 75395b66c587..68cc6c65ae5a 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -427,6 +427,7 @@ public function wait(callable $callback = null) } while ($running); while ($this->isRunning()) { + $this->checkTimeout(); usleep(1000); } diff --git a/src/Symfony/Component/Process/Tests/ErrorProcessInitiator.php b/src/Symfony/Component/Process/Tests/ErrorProcessInitiator.php new file mode 100755 index 000000000000..c37aeb5c8ffd --- /dev/null +++ b/src/Symfony/Component/Process/Tests/ErrorProcessInitiator.php @@ -0,0 +1,36 @@ + + * + * 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; +} diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index a9ecbe8043f6..18fef4ff5ff1 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -1551,6 +1551,15 @@ public function testEnvArgument() $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|null $cwd