Skip to content

Commit 6d8b5f5

Browse files
committed
Fixed tests for configurations related to the CONF_HINT_CON_RECV_TIMEOUT feature
1 parent 3dbd78e commit 6d8b5f5

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

src/Bolt/BoltResult.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Laudis\Neo4j\Databags\Neo4jError;
2828
use Laudis\Neo4j\Exception\Neo4jException;
2929
use Laudis\Neo4j\Formatter\SummarizedResultFormatter;
30+
use Throwable;
3031

3132
/**
3233
* @psalm-import-type BoltCypherStats from SummarizedResultFormatter

src/BoltFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function createConnection(ConnectionRequestData $data, SessionConfigurati
8080
$config->setServerAgent($response['server']);
8181

8282
// Apply recv_timeout hint if present
83-
if (array_key_exists('connection.recv_timeout_seconds', $response['hints'])) {
83+
if (array_key_exists('hints', $response) && array_key_exists('connection.recv_timeout_seconds', $response['hints'])) {
8484
$connection->setTimeout((float) $response['hints']['connection.recv_timeout_seconds']);
8585
}
8686

@@ -97,7 +97,7 @@ public function canReuseConnection(ConnectionInterface $connection, SessionConfi
9797
$database = $databaseInfo?->getName();
9898

9999
return $connection->getAccessMode() === $config->getAccessMode()
100-
&& $database === $config->getDatabase();
100+
&& $database === $config->getDatabase();
101101
}
102102

103103
public function reuseConnection(BoltConnection $connection, SessionConfiguration $sessionConfig): BoltConnection

src/Contracts/BoltMessage.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,21 @@ public function getResponse(): Response
3737
try {
3838
$response = $this->connection->protocol()->getResponse();
3939
} catch (Throwable $e) {
40-
// Convert socket timeout and I/O exceptions to Neo4jException
41-
$message = strtolower($e->getMessage());
42-
4340
if ($this->isTimeoutException($e)) {
44-
// Extract timeout value from the exception message if available
4541
$timeoutMsg = 'Connection timeout reached';
46-
if (preg_match('/(\d+)\s*(?:milliseconds?|ms|seconds?|s)/', $e->getMessage(), $matches)) {
42+
if (preg_match('/(\d+)\s*(?:milliseconds?|ms|seconds?|s)/', $e->getMessage(), $matches) && array_key_exists(1, $matches)) {
4743
$timeoutMsg = 'Connection timeout reached after '.$matches[1].' seconds';
4844
}
49-
// Close the connection to mark it as unusable
5045
try {
5146
$this->connection->close();
5247
} catch (Throwable) {
53-
// Ignore errors when closing a broken connection
5448
}
5549
// Use DriverError so the driver treats this as a failure
5650
throw new Neo4jException([Neo4jError::fromMessageAndCode('Neo.ClientError.Cluster.NotALeader', $timeoutMsg)], $e);
5751
} elseif ($this->isSocketException($e)) {
58-
// Handle socket errors (broken pipe, connection reset, etc.)
5952
try {
6053
$this->connection->close();
6154
} catch (Throwable) {
62-
// Ignore errors when closing a broken connection
6355
}
6456
throw new Neo4jException([Neo4jError::fromMessageAndCode('Neo.ClientError.Cluster.NotALeader', 'Connection error: '.$e->getMessage())], $e);
6557
}

0 commit comments

Comments
 (0)