Skip to content

Commit c5f8a2c

Browse files
authored
Merge pull request #56 from SimonFrings/unhandled-rejections
Update close handler to avoid unhandled promise rejections
2 parents b9e1912 + 703bcbb commit c5f8a2c

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/ProxyConnector.php

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ public function connect($uri)
159159
// either close active connection or cancel pending connection attempt
160160
$connecting->then(function (ConnectionInterface $stream) {
161161
$stream->close();
162+
}, function () {
163+
// ignore to avoid reporting unhandled rejection
162164
});
163165
$connecting->cancel();
164166
});

tests/ProxyConnectorTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,9 @@ public function testRejectedConnectionShouldNotCreateGarbageCycles()
542542
$proxy = new ProxyConnector('proxy.example.com', $this->connector);
543543

544544
$promise = $proxy->connect('google.com:80');
545+
546+
$promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection
547+
545548
unset($promise);
546549

547550
$this->assertEquals(0, gc_collect_cycles());

0 commit comments

Comments
 (0)