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:
parent
cc3357d003
commit
586d662b58
@ -24,6 +24,9 @@ final class Handle extends ProcessHandle {
|
||||
/** @var string */
|
||||
public $extraDataPipeWatcher;
|
||||
|
||||
/** @var string */
|
||||
public $extraDataPipeStartWatcher;
|
||||
|
||||
/** @var int */
|
||||
public $originalParentPid;
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user