From c94dde4541eaced0c8d83933cdfe1fb56136b90f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 17 Oct 2026 15:09:38 +0200 Subject: [PATCH] Update idle handler to avoid unhandled promise rejections --- src/SshSocksConnector.php | 2 ++ tests/IntegrationSshSocksConnectorTest.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) 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');