From 4edc68ef1a59d4096a34de3054ec00636ffe636f Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Fri, 24 Oct 2025 13:35:29 -0400 Subject: [PATCH] Catch fatal exception in stream_socket_client --- src/TcpConnector.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/TcpConnector.php b/src/TcpConnector.php index 9d2599e..161b74a 100644 --- a/src/TcpConnector.php +++ b/src/TcpConnector.php @@ -88,14 +88,21 @@ public function connect($uri) // HHVM fails to parse URIs with a query but no path, so let's simplify our URI here $remote = 'tcp://' . $parts['host'] . ':' . $parts['port']; - $stream = @\stream_socket_client( - $remote, - $errno, - $errstr, - 0, - \STREAM_CLIENT_CONNECT | \STREAM_CLIENT_ASYNC_CONNECT, - \stream_context_create($context) - ); + try { + $stream = @\stream_socket_client( + $remote, + $errno, + $errstr, + 0, + \STREAM_CLIENT_CONNECT | \STREAM_CLIENT_ASYNC_CONNECT, + \stream_context_create($context) + ); + } catch (\Exception $e) { + return Promise\reject(new \RuntimeException( + 'Connection to ' . $uri . ' failed: ' . $errstr . SocketServer::errconst($errno), + $errno + )); + } if (false === $stream) { return Promise\reject(new \RuntimeException(