Skip to content

Commit 7b30620

Browse files
[Process] Don't wait for the process after timeout
1 parent 800232c commit 7b30620

File tree

3 files changed

+9
-25
lines changed

3 files changed

+9
-25
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,7 @@ public function __construct($commandline, $cwd = null, array $env = null, $stdin
157157

158158
public function __destruct()
159159
{
160-
if ($this->isRunning()) {
161-
$this->doSignal(15, false);
162-
usleep(10000);
163-
}
164-
if ($this->isRunning()) {
165-
usleep(100000);
166-
$this->doSignal(9, false);
167-
}
168-
169-
// Don't call ->stop() nor ->close() since we don't want to wait for the subprocess here
160+
$this->stop(0);
170161
}
171162

172163
public function __clone()
@@ -678,7 +669,7 @@ public function stop($timeout = 10, $signal = null)
678669

679670
$this->updateStatus(false);
680671
if ($this->processInformation['running']) {
681-
$this->close();
672+
$this->close(false);
682673
}
683674

684675
return $this->exitcode;
@@ -1061,7 +1052,7 @@ protected function updateStatus($blocking)
10611052
$this->readPipes($blocking, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
10621053

10631054
if (!$this->processInformation['running']) {
1064-
$this->close();
1055+
$this->close(true);
10651056
}
10661057
}
10671058

@@ -1123,12 +1114,14 @@ private function captureExitCode()
11231114
/**
11241115
* Closes process resource, closes file handles, sets the exitcode.
11251116
*
1117+
* @param bool $wait Whether to wait for the end of the process or not.
1118+
*
11261119
* @return int The exitcode
11271120
*/
1128-
private function close()
1121+
private function close($wait)
11291122
{
11301123
$this->processPipes->close();
1131-
if (is_resource($this->process)) {
1124+
if ($wait && is_resource($this->process)) {
11321125
$exitcode = proc_close($this->process);
11331126
} else {
11341127
$exitcode = -1;
@@ -1148,6 +1141,7 @@ private function close()
11481141
// Doing so in other contexts like __destruct or by garbage collector is ineffective
11491142
// Now pipes are closed, so the callback is no longer necessary
11501143
$this->callback = null;
1144+
$this->process = null;
11511145

11521146
return $this->exitcode;
11531147
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,7 @@ public function testCheckTimeoutOnStartedProcess()
727727
}
728728
$duration = microtime(true) - $start;
729729

730-
$this->assertLessThan($timeout + $precision, $duration);
731-
$this->assertFalse($process->isSuccessful());
730+
$this->assertLessThan($timeout + $precision / 1E6, $duration);
732731

733732
throw $e;
734733
}

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,6 @@ public function testProcessWithoutTermSignal()
8585
parent::testProcessWithoutTermSignal();
8686
}
8787

88-
/**
89-
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
90-
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.
91-
*/
92-
public function testCheckTimeoutOnStartedProcess()
93-
{
94-
parent::testCheckTimeoutOnStartedProcess();
95-
}
96-
9788
/**
9889
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
9990
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.

0 commit comments

Comments
 (0)