diff --git a/src/future/exec/ExecFuture.php b/src/future/exec/ExecFuture.php --- a/src/future/exec/ExecFuture.php +++ b/src/future/exec/ExecFuture.php @@ -426,7 +426,10 @@ public function resolveKill() { if (!$this->result) { $signal = 9; - proc_terminate($this->proc, $signal); + + if ($this->proc) { + proc_terminate($this->proc, $signal); + } $this->result = array( 128 + $signal, diff --git a/src/future/exec/__tests__/ExecFutureTestCase.php b/src/future/exec/__tests__/ExecFutureTestCase.php --- a/src/future/exec/__tests__/ExecFutureTestCase.php +++ b/src/future/exec/__tests__/ExecFutureTestCase.php @@ -63,6 +63,14 @@ $future->resolve(); } + public function testTerminateWithoutStart() { + // We never start this future, but it should be fine to kill a future from + // any state. + $future = new ExecFuture('sleep 1'); + $future->resolveKill(); + + $this->assertTrue(true); + } public function testTimeoutTestShouldRunLessThan1Sec() { // NOTE: This is partly testing that we choose appropriate select wait