Skip to content

Commit ed3fc9f

Browse files
committed
bug symfony#20600 [Process] Fix process continuing after reached timeout using getIterator() (chalasr)
This PR was merged into the 3.1 branch. Discussion ---------- [Process] Fix process continuing after reached timeout using getIterator() | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#20594 | License | MIT | Doc PR | n/a Commits ------- 10992cd [Process] Fix kill process on reached timeout using getIterator()
2 parents 08c869e + 10992cd commit ed3fc9f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Symfony/Component/Process/Process.php

+1
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ public function getIterator($flags = 0)
557557
yield self::OUT => '';
558558
}
559559

560+
$this->checkTimeout();
560561
$this->readPipesForOutput(__FUNCTION__, $blocking);
561562
}
562563
}

src/Symfony/Component/Process/Tests/ProcessTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,27 @@ public function testRunProcessWithTimeout()
747747
throw $e;
748748
}
749749

750+
/**
751+
* @expectedException \Symfony\Component\Process\Exception\ProcessTimedOutException
752+
* @expectedExceptionMessage exceeded the timeout of 0.1 seconds.
753+
*/
754+
public function testIterateOverProcessWithTimeout()
755+
{
756+
$process = $this->getProcess(self::$phpBin.' -r "sleep(30);"');
757+
$process->setTimeout(0.1);
758+
$start = microtime(true);
759+
try {
760+
$process->start();
761+
foreach ($process as $buffer);
762+
$this->fail('A RuntimeException should have been raised');
763+
} catch (RuntimeException $e) {
764+
}
765+
766+
$this->assertLessThan(15, microtime(true) - $start);
767+
768+
throw $e;
769+
}
770+
750771
public function testCheckTimeoutOnNonStartedProcess()
751772
{
752773
$process = $this->getProcess('echo foo');

0 commit comments

Comments
 (0)