Skip to content

Commit 9210a00

Browse files
committed
improved null check on table
1 parent 8b8f82a commit 9210a00

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/Neo4j/Neo4jConnectionPool.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Bolt\protocol\V4_4;
2222
use function count;
2323
use Exception;
24+
use function implode;
2425
use Laudis\Neo4j\Bolt\BoltConnection;
2526
use Laudis\Neo4j\Bolt\BoltConnectionPool;
2627
use Laudis\Neo4j\Common\Uri;
@@ -78,25 +79,23 @@ public function acquire(
7879
$key = $uri->getHost().':'.($uri->getPort() ?? '7687');
7980

8081
$table = self::$routingCache[$key] ?? null;
82+
$triedAddresses = [];
8183
if ($table === null || $table->getTtl() < time()) {
8284
$addresses = $this->resolver->getAddresses($uri->getHost());
83-
$triedAddresses = [];
84-
$canConnect = false;
8585
foreach ($addresses as $address) {
8686
$triedAddresses[] = $address;
8787
if ($this->pool->canConnect($uri->withHost($address), $authenticate)) {
88-
$canConnect = true;
8988
$connection = $this->pool->acquire($uri->withHost($address), $authenticate, $config);
9089
$table = $this->routingTable($connection, $config);
9190
self::$routingCache[$key] = $table;
9291
$connection->close();
9392
break;
9493
}
9594
}
95+
}
9696

97-
if (!$canConnect) {
98-
throw new RuntimeException(sprintf('Cannot connect to host: "%s". Hosts tried: "%s"', $uri->getHost(), implode('", "', $triedAddresses)));
99-
}
97+
if ($table === null) {
98+
throw new RuntimeException(sprintf('Cannot connect to host: "%s". Hosts tried: "%s"', $uri->getHost(), implode('", "', $triedAddresses)));
10099
}
101100

102101
$server = $this->getNextServer($table, $config->getAccessMode()) ?? $uri;

0 commit comments

Comments
 (0)