1
0
mirror of https://github.com/danog/process.git synced 2024-12-04 10:38:04 +01:00

Fix issue with non-cancelled watcher

This commit is contained in:
Niklas Keller 2017-09-17 20:45:36 +02:00
parent cc3357d003
commit 586d662b58
2 changed files with 22 additions and 5 deletions

View File

@ -24,6 +24,9 @@ final class Handle extends ProcessHandle {
/** @var string */
public $extraDataPipeWatcher;
/** @var string */
public $extraDataPipeStartWatcher;
/** @var int */
public $originalParentPid;
}

View File

@ -103,7 +103,7 @@ final class Runner implements ProcessRunner {
\stream_set_blocking($pipes[3], false);
Loop::onReadable($pipes[3], [self::class, 'onProcessStartExtraDataPipeReadable'], [$handle, [
$handle->extraDataPipeStartWatcher = Loop::onReadable($pipes[3], [self::class, 'onProcessStartExtraDataPipeReadable'], [$handle, [
new ResourceOutputStream($pipes[0]),
new ResourceInputStream($pipes[1]),
new ResourceInputStream($pipes[2]),
@ -131,15 +131,21 @@ final class Runner implements ProcessRunner {
/** @inheritdoc */
public function kill(ProcessHandle $handle) {
/** @var Handle $handle */
if (!\proc_terminate($handle->proc, 9)) { // Forcefully kill the process using SIGKILL.
throw new ProcessException("Terminating process failed");
}
if ($handle->extraDataPipeWatcher !== null) {
Loop::cancel($handle->extraDataPipeWatcher);
$handle->extraDataPipeWatcher = null;
}
/** @var Handle $handle */
if ($handle->extraDataPipeStartWatcher !== null) {
Loop::cancel($handle->extraDataPipeStartWatcher);
$handle->extraDataPipeStartWatcher = null;
}
if (!\proc_terminate($handle->proc, 9)) { // Forcefully kill the process using SIGKILL.
throw new ProcessException("Terminating process failed");
}
$handle->status = ProcessStatus::ENDED;
$handle->joinDeferred->fail(new ProcessException("The process was killed"));
}
@ -159,8 +165,16 @@ final class Runner implements ProcessRunner {
$this->kill($handle);
}
/** @var Handle $handle */
if ($handle->extraDataPipeWatcher !== null) {
Loop::cancel($handle->extraDataPipeWatcher);
$handle->extraDataPipeWatcher = null;
}
/** @var Handle $handle */
if ($handle->extraDataPipeStartWatcher !== null) {
Loop::cancel($handle->extraDataPipeStartWatcher);
$handle->extraDataPipeStartWatcher = null;
}
if (\is_resource($handle->extraDataPipe)) {