diff --git a/composer.json b/composer.json index 2cbc0f1..9937145 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "expensify/bedrock-php", "description": "Bedrock PHP Library", "type": "library", - "version": "2.2.6", + "version": "2.2.7", "authors": [ { "name": "Expensify", diff --git a/src/Client.php b/src/Client.php index f01679a..6182162 100644 --- a/src/Client.php +++ b/src/Client.php @@ -577,6 +577,12 @@ private function sendRawRequest(string $host, int $port, string $rawRequest) @socket_connect($this->socket, $host, $port); $connectTime = (microtime(true) - $connectStart) * 1000; $socketErrorCode = socket_last_error($this->socket); + + // Get local socket information for logging (available after socket_connect call) + $localAddress = ''; + $localPort = 0; + socket_getsockname($this->socket, $localAddress, $localPort); + if ($socketErrorCode === 115) { $this->logger->info('Bedrock\Client - socket_connect returned error 115, waiting for connection to complete.', [ 'host' => $host, @@ -597,6 +603,24 @@ private function sendRawRequest(string $host, int $port, string $rawRequest) $socketError = socket_strerror(socket_last_error($this->socket)); throw new ConnectionFailure("socket_select failed after EINPROGRESS for $host:$port. Error: $socketError"); } elseif ($selectResult === 0) { + // Check if there's a pending error on the socket that might explain the timeout + $pendingError = socket_get_option($this->socket, SOL_SOCKET, SO_ERROR); + $pendingErrorStr = $pendingError ? socket_strerror($pendingError) : 'none'; + + // Get socket buffer sizes to check for misconfigurations + $sendBufferSize = socket_get_option($this->socket, SOL_SOCKET, SO_SNDBUF); + $receiveBufferSize = socket_get_option($this->socket, SOL_SOCKET, SO_RCVBUF); + + $this->logger->info('Bedrock\Client - Socket timeout after EINPROGRESS', [ + 'localAddress' => $localAddress, + 'localPort' => $localPort, + 'remoteHost' => $host, + 'remotePort' => $port, + 'pendingErrorCode' => $pendingError, + 'pendingError' => $pendingErrorStr, + 'sendBufferSize' => $sendBufferSize, + 'receiveBufferSize' => $receiveBufferSize, + ]); throw new ConnectionFailure("Socket not ready for writing within timeout after EINPROGRESS for $host:$port"); } elseif (empty($write)) { $socketErrorCode = socket_last_error($this->socket);