Skip to content

Commit 9844fbb

Browse files
Merge pull request #245 from Expensify/jpersaud_log_socket
Add more logging on socket timeouts
2 parents 02142e5 + a016010 commit 9844fbb

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "expensify/bedrock-php",
33
"description": "Bedrock PHP Library",
44
"type": "library",
5-
"version": "2.2.6",
5+
"version": "2.2.7",
66
"authors": [
77
{
88
"name": "Expensify",

src/Client.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)