Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Basic/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ public static function create(string|UriInterface $uri, ?DriverConfiguration $co

return new self($driver);
}

public function closeConnections(): void
{
$this->driver->closeConnections();
}
}
37 changes: 32 additions & 5 deletions src/Bolt/BoltConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,23 @@ public function getAuthentication(): AuthenticateInterface
*/
public function isOpen(): bool
{
return !in_array($this->protocol()->serverState, [ServerState::DISCONNECTED, ServerState::DEFUNCT], true);
return !in_array(
$this->protocol()->serverState,
[ServerState::DISCONNECTED, ServerState::DEFUNCT],
true
);
}

/**
* @psalm-mutation-free
*/
public function isStreaming(): bool
{
return in_array(
$this->protocol()->serverState,
[ServerState::STREAMING, ServerState::TX_STREAMING],
true
);
}

public function setTimeout(float $timeout): void
Expand All @@ -154,7 +170,7 @@ public function setTimeout(float $timeout): void
public function consumeResults(): void
{
$this->logger?->log(LogLevel::DEBUG, 'Consuming results');
if ($this->protocol()->serverState !== ServerState::STREAMING && $this->protocol()->serverState !== ServerState::TX_STREAMING) {
if (!$this->isStreaming()) {
$this->subscribedResults = [];

return;
Expand Down Expand Up @@ -225,8 +241,14 @@ public function discard(?int $qid): void
*
* @return BoltMeta
*/
public function run(string $text, array $parameters, ?string $database, ?float $timeout, BookmarkHolder $holder, ?AccessMode $mode): array
{
public function run(
string $text,
array $parameters,
?string $database,
?float $timeout,
BookmarkHolder $holder,
?AccessMode $mode
): array {
$extra = $this->buildRunExtra($database, $timeout, $holder, $mode);
$this->logger?->log(LogLevel::DEBUG, 'RUN', $extra);
$response = $this->protocol()
Expand Down Expand Up @@ -298,10 +320,15 @@ public function pull(?int $qid, ?int $fetchSize): array
}

public function __destruct()
{
$this->close();
}

public function close(): void
{
try {
if ($this->isOpen()) {
if ($this->protocol()->serverState === ServerState::STREAMING || $this->protocol()->serverState === ServerState::TX_STREAMING) {
if ($this->isStreaming()) {
$this->consumeResults();
}

Expand Down
5 changes: 5 additions & 0 deletions src/Bolt/BoltDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ public function verifyConnectivity(?SessionConfiguration $config = null): bool

return true;
}

public function closeConnections(): void
{
$this->pool->close();
}
}
16 changes: 14 additions & 2 deletions src/Bolt/ConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ public function __construct(
private readonly ?Neo4jLogger $logger
) {}

public static function create(UriInterface $uri, AuthenticateInterface $auth, DriverConfiguration $conf, SemaphoreInterface $semaphore): self
{
public static function create(
UriInterface $uri,
AuthenticateInterface $auth,
DriverConfiguration $conf,
SemaphoreInterface $semaphore
): self {
return new self(
$semaphore,
BoltFactory::create($conf->getLogger()),
Expand Down Expand Up @@ -165,4 +169,12 @@ private function returnAnyAvailableConnection(SessionConfiguration $config): ?Co

return null;
}

public function close(): void
{
foreach ($this->activeConnections as $activeConnection) {
$activeConnection->close();
}
$this->activeConnections = [];
}
}
5 changes: 5 additions & 0 deletions src/Contracts/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,9 @@ public function getEncryptionLevel(): string;
* Returns the user agent handling this connection.
*/
public function getUserAgent(): string;

/**
* Closes the connection.
*/
public function close(): void;
}
5 changes: 5 additions & 0 deletions src/Contracts/ConnectionPoolInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public function acquire(SessionConfiguration $config): Generator;
* Releases a connection back to the pool.
*/
public function release(ConnectionInterface $connection): void;

/**
* Closes all connections in the pool.
*/
public function close(): void;
}
5 changes: 5 additions & 0 deletions src/Contracts/DriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public function createSession(?SessionConfiguration $config = null): SessionInte
* Returns true if the driver can make a valid connection with the server.
*/
public function verifyConnectivity(?SessionConfiguration $config = null): bool;

/**
* Closes all connections in the pool.
*/
public function closeConnections(): void;
}
5 changes: 5 additions & 0 deletions src/Http/HttpConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,9 @@ public function release(ConnectionInterface $connection): void
{
// Nothing to release in the current HTTP Protocol implementation
}

public function close(): void
{
// Nothing to close in the current HTTP Protocol implementation
}
}
5 changes: 5 additions & 0 deletions src/Http/HttpDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,9 @@ private function tsxUrl(SessionConfiguration $config): Resolvable
return str_replace('{databaseName}', $database, $tsx);
});
}

public function closeConnections(): void
{
// Nothing to close in the current HTTP Protocol implementation
}
}
9 changes: 9 additions & 0 deletions src/Neo4j/Neo4jConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,13 @@ private function createKey(ConnectionRequestData $data, ?SessionConfiguration $c
':',
], '|', $key);
}

public function close(): void
{
foreach (self::$pools as $pool) {
$pool->close();
}
self::$pools = [];
$this->cache->clear();
}
}
5 changes: 5 additions & 0 deletions src/Neo4j/Neo4jDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,9 @@ public function verifyConnectivity(?SessionConfiguration $config = null): bool

return true;
}

public function closeConnections(): void
{
$this->pool->close();
}
}