Skip to content

Commit 4b813ec

Browse files
authored
Merge pull request #229 from Expensify/flo_EINPROGRESS
2 parents 08d089c + 0a22a64 commit 4b813ec

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
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.1.2",
5+
"version": "2.1.3",
66
"authors": [
77
{
88
"name": "Expensify",

src/Client.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,29 @@ private function sendRawRequest(string $host, int $port, string $rawRequest)
552552
@socket_connect($this->socket, $host, $port);
553553
$socketErrorCode = socket_last_error($this->socket);
554554
if ($socketErrorCode === 115) {
555-
$this->logger->info('Bedrock\Client - socket_connect returned error 115, continuing.');
555+
$this->logger->info('Bedrock\Client - socket_connect returned EINPROGRESS, waiting for connection to complete');
556+
557+
// Use select to wait for the socket to become writable (indicates connection completion)
558+
$write = [$this->socket];
559+
$read = null;
560+
$except = null;
561+
562+
$selectResult = socket_select($read, $write, $except, $this->connectionTimeout, $this->connectionTimeoutMicroseconds);
563+
if ($selectResult === false) {
564+
$socketError = socket_strerror(socket_last_error());
565+
throw new ConnectionFailure("Failed to select on socket for host $host:$port. Error: $socketError");
566+
} elseif ($selectResult === 0) {
567+
throw new ConnectionFailure("Connection timeout while waiting for EINPROGRESS completion for host $host:$port");
568+
}
569+
570+
// Check if connection completed successfully
571+
$connectionError = socket_get_option($this->socket, SOL_SOCKET, SO_ERROR);
572+
if ($connectionError !== 0) {
573+
$socketError = socket_strerror($connectionError);
574+
throw new ConnectionFailure("Connection failed after EINPROGRESS for host $host:$port. Error: $connectionError $socketError");
575+
}
576+
577+
$this->logger->info('Bedrock\Client - EINPROGRESS connection completed successfully');
556578
} elseif ($socketErrorCode) {
557579
$socketError = socket_strerror($socketErrorCode);
558580
throw new ConnectionFailure("Could not connect to Bedrock host $host:$port. Error: $socketErrorCode $socketError");

0 commit comments

Comments
 (0)