From 703bcbbbf45c088d94114fa309c28800cf6deb92 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Tue, 9 Apr 2024 09:49:12 +0200 Subject: [PATCH] Update close handler to avoid unhandled promise rejections --- src/ProxyConnector.php | 2 ++ tests/ProxyConnectorTest.php | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/ProxyConnector.php b/src/ProxyConnector.php index 165e8ba..d7f2863 100644 --- a/src/ProxyConnector.php +++ b/src/ProxyConnector.php @@ -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(); }); diff --git a/tests/ProxyConnectorTest.php b/tests/ProxyConnectorTest.php index 0b8c155..f2d5795 100644 --- a/tests/ProxyConnectorTest.php +++ b/tests/ProxyConnectorTest.php @@ -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());