@@ -577,6 +577,12 @@ private function sendRawRequest(string $host, int $port, string $rawRequest)
577577 @socket_connect ($ this ->socket , $ host , $ port );
578578 $ connectTime = (microtime (true ) - $ connectStart ) * 1000 ;
579579 $ socketErrorCode = socket_last_error ($ this ->socket );
580+
581+ // Get local socket information for logging (available after socket_connect call)
582+ $ localAddress = '' ;
583+ $ localPort = 0 ;
584+ socket_getsockname ($ this ->socket , $ localAddress , $ localPort );
585+
580586 if ($ socketErrorCode === 115 ) {
581587 $ this ->logger ->info ('Bedrock\Client - socket_connect returned error 115, waiting for connection to complete. ' , [
582588 'host ' => $ host ,
@@ -597,6 +603,24 @@ private function sendRawRequest(string $host, int $port, string $rawRequest)
597603 $ socketError = socket_strerror (socket_last_error ($ this ->socket ));
598604 throw new ConnectionFailure ("socket_select failed after EINPROGRESS for $ host: $ port. Error: $ socketError " );
599605 } elseif ($ selectResult === 0 ) {
606+ // Check if there's a pending error on the socket that might explain the timeout
607+ $ pendingError = socket_get_option ($ this ->socket , SOL_SOCKET , SO_ERROR );
608+ $ pendingErrorStr = $ pendingError ? socket_strerror ($ pendingError ) : 'none ' ;
609+
610+ // Get socket buffer sizes to check for misconfigurations
611+ $ sendBufferSize = socket_get_option ($ this ->socket , SOL_SOCKET , SO_SNDBUF );
612+ $ receiveBufferSize = socket_get_option ($ this ->socket , SOL_SOCKET , SO_RCVBUF );
613+
614+ $ this ->logger ->info ('Bedrock\Client - Socket timeout after EINPROGRESS ' , [
615+ 'localAddress ' => $ localAddress ,
616+ 'localPort ' => $ localPort ,
617+ 'remoteHost ' => $ host ,
618+ 'remotePort ' => $ port ,
619+ 'pendingErrorCode ' => $ pendingError ,
620+ 'pendingError ' => $ pendingErrorStr ,
621+ 'sendBufferSize ' => $ sendBufferSize ,
622+ 'receiveBufferSize ' => $ receiveBufferSize ,
623+ ]);
600624 throw new ConnectionFailure ("Socket not ready for writing within timeout after EINPROGRESS for $ host: $ port " );
601625 } elseif (empty ($ write )) {
602626 $ socketErrorCode = socket_last_error ($ this ->socket );
0 commit comments