Skip to content

Commit 6912ffd

Browse files
authored
Merge pull request #52 from clue-labs/unhandled-rejections
Update idle handler to avoid unhandled promise rejections
2 parents 0d4ac33 + c94dde4 commit 6912ffd

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎src/SshSocksConnector.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ public function idle()
198198
$this->idleTimer = $this->loop->addTimer($this->idlePeriod, function () use (&$listen, $debug) {
199199
$listen->then(function (Process $process) {
200200
$process->terminate();
201+
}, function () {
202+
// ignore to avoid reporting unhandled rejection
201203
});
202204
$listen->cancel();
203205
$listen = null;

‎tests/IntegrationSshSocksConnectorTest.php‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ public function testConnectWillRejectWithExceptionAndTerminateIdleProcessWhenSoc
118118
$this->assertTrue($process->isTerminated());
119119
}
120120

121+
public function testConnectCancellationWillRejectWithException()
122+
{
123+
$connector = new SshSocksConnector('host');
124+
125+
$ref = new \ReflectionProperty($connector, 'cmd');
126+
if (PHP_VERSION_ID < 80100) {
127+
$ref->setAccessible(true);
128+
}
129+
$ref->setValue($connector, 'exec sleep 10; #');
130+
131+
$promise = $connector->connect('example.com:80');
132+
$promise->cancel();
133+
134+
$promise->then(null, $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));
135+
136+
Loop::run();
137+
}
138+
121139
public function testConnectWillRejectWithExceptionAndTerminateProcessWhenProcessOutputsLineExceedingMaximumBufferSize()
122140
{
123141
$connector = new SshSocksConnector('host');

0 commit comments

Comments
 (0)