@@ -438,26 +438,6 @@ public function call($method, $headers = [], $body = '')
438438 $ this ->sendRawRequest ($ hostName , $ port , $ rawRequest );
439439 $ response = $ this ->receiveResponse ();
440440 } catch (ConnectionFailure $ e ) {
441- // Debug EAGAIN errors - check socket state when error occurs
442- $ lastSocketError = $ this ->socket ? socket_last_error ($ this ->socket ) : null ;
443-
444- // Log more data to diagnose problems with EAGAIN/EWOULDBLOCK
445- if ($ lastSocketError === 11 ) {
446- $ write = [$ this ->socket ];
447- $ read = [];
448- $ except = [];
449- $ selectResult = socket_select ($ read , $ write , $ except , 0 , 0 );
450-
451- $ this ->logger ->info ('EAGAIN Debugging information ' , [
452- 'host ' => $ hostName ,
453- 'socket_ready_for_writing ' => ($ selectResult === 1 && !empty ($ write )) ? 'YES ' : 'NO ' ,
454- 'socket_was_reused ' => $ this ->lastHost === $ hostName && $ this ->socket !== null ,
455- 'last_host ' => $ this ->lastHost ,
456- 'current_host ' => $ hostName ,
457- 'pid ' => getmypid (),
458- ]);
459- }
460-
461441 // The error happened during connection (or before we sent any data, or in a case where we know the
462442 // command was never processed) so we can retry it safely.
463443 $ this ->markHostAsFailed ($ hostName );
@@ -567,78 +547,12 @@ private function sendRawRequest(string $host, int $port, string $rawRequest)
567547 }
568548
569549 // Configure this socket and try to connect to it
570- // Use non-blocking mode for connection to avoid timeouts. On non-blocking sockets, socket_connect()
571- // may return immediately for reasons unclear with EINPROGRESS (error 115), allowing us to use socket_select() to wait
572- // with a proper timeout. This prevents connection attempts from hanging indefinitely.
573- socket_set_nonblock ($ this ->socket );
574550 socket_set_option ($ this ->socket , SOL_SOCKET , SO_SNDTIMEO , ['sec ' => $ this ->connectionTimeout , 'usec ' => $ this ->connectionTimeoutMicroseconds ]);
575551 socket_set_option ($ this ->socket , SOL_SOCKET , SO_RCVTIMEO , ['sec ' => $ this ->readTimeout , 'usec ' => $ this ->readTimeoutMicroseconds ]);
576- $ connectStart = microtime (true );
577552 @socket_connect ($ this ->socket , $ host , $ port );
578- $ connectTime = (microtime (true ) - $ connectStart ) * 1000 ;
579553 $ 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-
586554 if ($ socketErrorCode === 115 ) {
587- $ this ->logger ->info ('Bedrock\Client - socket_connect returned error 115, waiting for connection to complete. ' , [
588- 'host ' => $ host ,
589- 'connectAttemptTimeMs ' => round ($ connectTime , 3 ),
590- ]);
591-
592- // Wait for the socket to be ready for writing after EINPROGRESS
593- $ write = [$ this ->socket ];
594- $ read = [];
595- $ except = [];
596- $ selectStart = microtime (true );
597- $ selectResult = socket_select ($ read , $ write , $ except , $ this ->connectionTimeout , $ this ->connectionTimeoutMicroseconds );
598-
599- // Time for socket_select call
600- $ selectTime = (microtime (true ) - $ selectStart ) * 1000 ;
601-
602- if ($ selectResult === false ) {
603- $ socketError = socket_strerror (socket_last_error ($ this ->socket ));
604- throw new ConnectionFailure ("socket_select failed after EINPROGRESS for $ host: $ port. Error: $ socketError " );
605- } 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- ]);
624- throw new ConnectionFailure ("Socket not ready for writing within timeout after EINPROGRESS for $ host: $ port " );
625- } elseif (empty ($ write )) {
626- $ socketErrorCode = socket_last_error ($ this ->socket );
627- $ socketError = socket_strerror ($ socketErrorCode );
628- throw new ConnectionFailure ("Socket had error after EINPROGRESS for $ host: $ port. Error: $ socketErrorCode $ socketError " );
629- }
630-
631- // Total time from connect to ready
632- $ totalTime = (microtime (true ) - $ connectStart ) * 1000 ;
633-
634- // Set socket back to blocking mode for normal operations
635- socket_set_block ($ this ->socket );
636-
637- $ this ->logger ->info ('Bedrock\Client - Socket ready for writing after EINPROGRESS. ' , [
638- 'host ' => $ host ,
639- 'totalConnectionTimeMs ' => round ($ totalTime , 3 ),
640- 'selectWaitTimeMs ' => round ($ selectTime , 3 ),
641- ]);
555+ $ this ->logger ->info ('Bedrock\Client - socket_connect returned error 115, continuing. ' );
642556 } elseif ($ socketErrorCode ) {
643557 $ socketError = socket_strerror ($ socketErrorCode );
644558 throw new ConnectionFailure ("Could not connect to Bedrock host $ host: $ port. Error: $ socketErrorCode $ socketError " );
0 commit comments