Skip to content

Commit

Permalink
Update close handler to avoid unhandled promise rejections
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFrings committed Apr 9, 2024
1 parent b9e1912 commit 703bcbb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ProxyConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public function connect($uri)
// either close active connection or cancel pending connection attempt
$connecting->then(function (ConnectionInterface $stream) {
$stream->close();
}, function () {
// ignore to avoid reporting unhandled rejection
});
$connecting->cancel();
});
Expand Down
3 changes: 3 additions & 0 deletions tests/ProxyConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@ public function testRejectedConnectionShouldNotCreateGarbageCycles()
$proxy = new ProxyConnector('proxy.example.com', $this->connector);

$promise = $proxy->connect('google.com:80');

$promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection

unset($promise);

$this->assertEquals(0, gc_collect_cycles());
Expand Down

0 comments on commit 703bcbb

Please sign in to comment.