Skip to content

Commit

Permalink
fix: boltProtocol reused after being unset via destructor
Browse files Browse the repository at this point in the history
  • Loading branch information
exaby73 committed Oct 16, 2024
1 parent ef3b137 commit c4ea84b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/Bolt/BoltConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ public function getImplementation(): array
* @psalm-mutation-free
*/
public function __construct(
private V4_4|V5|V5_1|V5_2|V5_3|V5_4 $boltProtocol,
private V4_4|V5|V5_1|V5_2|V5_3|V5_4|null $boltProtocol,
private readonly Connection $connection,
private readonly AuthenticateInterface $auth,
private readonly string $userAgent,
/** @psalm-readonly */
private readonly ConnectionConfiguration $config,
private readonly ?Neo4jLogger $logger,
) {}
) {
}

public function getEncryptionLevel(): string
{
Expand Down Expand Up @@ -143,6 +144,10 @@ public function getAuthentication(): AuthenticateInterface
*/
public function isOpen(): bool
{
if (!isset($this->boltProtocol)) {
return false;
}

return !in_array(
$this->protocol()->serverState,
[ServerState::DISCONNECTED, ServerState::DEFUNCT],
Expand Down Expand Up @@ -293,6 +298,9 @@ public function rollback(): void

public function protocol(): V4_4|V5|V5_1|V5_2|V5_3|V5_4
{
if (!isset($this->boltProtocol)) {
throw new \Exception('Connection is closed');
}
return $this->boltProtocol;
}

Expand Down Expand Up @@ -348,7 +356,7 @@ private function buildRunExtra(?string $database, ?float $timeout, BookmarkHolde
$extra['db'] = $database;
}
if ($timeout !== null) {
$extra['tx_timeout'] = (int) ($timeout * 1000);
$extra['tx_timeout'] = (int)($timeout * 1000);
}

if (!$holder->getBookmark()->isEmpty()) {
Expand Down Expand Up @@ -378,6 +386,9 @@ private function buildResultExtra(?int $fetchSize, ?int $qid): array

public function getServerState(): string
{
if (!isset($this->boltProtocol)) {
return ServerState::DISCONNECTED->name;
}
return $this->protocol()->serverState->name;
}

Expand Down
4 changes: 4 additions & 0 deletions src/BoltFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public function createConnection(ConnectionRequestData $data, SessionConfigurati

public function canReuseConnection(ConnectionInterface $connection, ConnectionRequestData $data, SessionConfiguration $config): bool
{
if (!$connection->isOpen()) {
return false;
}

$databaseInfo = $connection->getDatabaseInfo();
$database = $databaseInfo?->getName();

Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/OIDCTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

namespace Laudis\Neo4j\Tests\Integration;

use PHPUnit\Framework\TestCase;
use function array_key_exists;

use Laudis\Neo4j\Authentication\Authenticate;
use Laudis\Neo4j\Basic\Driver;
use Laudis\Neo4j\Tests\EnvironmentAwareIntegrationTest;

/**
* @psalm-suppress MissingConstructor
*/
final class OIDCTest extends EnvironmentAwareIntegrationTest
final class OIDCTest extends TestCase
{
public function testConnect(): void
{
Expand Down

0 comments on commit c4ea84b

Please sign in to comment.