8000 merged branch romainneutron/timeout-restart (PR #9050) · symfony/symfony@8efd5ca · GitHub
[go: up one dir, main page]

Skip to content
10000

Commit 8efd5ca

Browse files
committed
merged branch romainneutron/timeout-restart (PR #9050)
This PR was merged into the 2.3 branch. Discussion ---------- [Process][2.3] Properly close pipes after a Process::stop call | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT When calling `Process::stop`, if the process does not stop before the end of the method, pipes are not close, `proc_close` is not called. I added a test that randomly fails without the patch : ``` phpunit --filter=testStartAfterATimeout --repeat 100 Tests/SimpleProcessTest.php PHPUnit 3.8-g55a6dd0 by Sebastian Bergmann. Configuration read from /Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/phpunit.xml.dist ....E.E......E.....E..........EE..............EEE..EE.......E.. 63 / 100 ( 63%) E.E................E....EE.......E... Time: 29.55 seconds, Memory: 6.75Mb There were 18 errors: 1) Symfony\Component\Process\Tests\SimpleProcessTest::testStartAfterATimeout fclose(): 89 is not a valid stream resource /Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/ProcessPipes.php:95 /Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/ProcessPipes.php:80 /Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/ProcessPipes.php:62 /Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Process.php:938 /Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Process.php:229 /Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/AbstractProcessTest.php:490 ``` And of course, I solved the issue, tests are now OK. Commits ------- d84df4c [Process] Properly close pipes after a Process::stop call
2 parents bb97f64 + d84df4c commit 8efd5ca

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,13 @@ public function stop($timeout = 10, $signal = null)
626626
$this->signal($signal ?: SIGKILL);
627627
}
628628
}
629+
}
629630

630-
$this->updateStatus(false);
631+
$this->updateStatus(false);
632+
if ($this->processInformation['running']) {
633+
$this->close();
631634
}
635+
632636
$this->status = self::STATUS_TERMINATED;
633637

634638
return $this->exitcode;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,21 @@ public function testCheckTimeoutOnStartedProcess()
477477
$this->assertFalse($process->isSuccessful());
478478
}
479479

480+
public function testStartAfterATimeout()
481+
{
482+
$process = $this->getProcess('php -r "while(true) {echo \'\'; usleep(1000); }"');
483+
$process->setTimeout(0.1);
484+
try {
485+
$process->run();
486+
$this->fail('An exception should have been raised.');
487+
} catch (\Exception $e) {
488+
489+
}
490+
$process->start();
491+
usleep(10000);
492+
$process->stop();
493+
}
494+
480495
public function testGetPid()
481496
{
482497
$process = $this->getProcess('php -r "sleep(1);"');

0 commit comments

Comments
 (0)
0