diff --git a/src/SshSocksConnector.php b/src/SshSocksConnector.php index 6a7197e..17a14a5 100644 --- a/src/SshSocksConnector.php +++ b/src/SshSocksConnector.php @@ -198,6 +198,8 @@ public function idle() $this->idleTimer = $this->loop->addTimer($this->idlePeriod, function () use (&$listen, $debug) { $listen->then(function (Process $process) { $process->terminate(); + }, function () { + // ignore to avoid reporting unhandled rejection }); $listen->cancel(); $listen = null; diff --git a/tests/IntegrationSshSocksConnectorTest.php b/tests/IntegrationSshSocksConnectorTest.php index aeb16ea..5f35d25 100644 --- a/tests/IntegrationSshSocksConnectorTest.php +++ b/tests/IntegrationSshSocksConnectorTest.php @@ -118,6 +118,24 @@ public function testConnectWillRejectWithExceptionAndTerminateIdleProcessWhenSoc $this->assertTrue($process->isTerminated()); } + public function testConnectCancellationWillRejectWithException() + { + $connector = new SshSocksConnector('host'); + + $ref = new \ReflectionProperty($connector, 'cmd'); + if (PHP_VERSION_ID < 80100) { + $ref->setAccessible(true); + } + $ref->setValue($connector, 'exec sleep 10; #'); + + $promise = $connector->connect('example.com:80'); + $promise->cancel(); + + $promise->then(null, $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException'))); + + Loop::run(); + } + public function testConnectWillRejectWithExceptionAndTerminateProcessWhenProcessOutputsLineExceedingMaximumBufferSize() { $connector = new SshSocksConnector('host');