Skip to content

Commit

Permalink
Always enqueue connection when pushed
Browse files Browse the repository at this point in the history
Changed syntax around Future usage to see if a PHP bug is causing suspension reuse.
  • Loading branch information
trowski committed Oct 2, 2024
1 parent 996b8ad commit 85449d5
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/SqlCommonConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,8 @@ protected function pop(): SqlConnection
if ($this->connections->count() < $this->getConnectionLimit()) {
// Max connection count has not been reached, so open another connection.
try {
$connection = (
$this->future = async(fn () => $this->connector->connect($this->config))
)->await();
$this->future = async(fn () => $this->connector->connect($this->config));
$connection = $this->future->await();
/** @psalm-suppress DocblockTypeContradiction */
if (!$connection instanceof SqlLink) {
throw new \Error(\sprintf(
Expand All @@ -289,10 +288,11 @@ protected function pop(): SqlConnection
// All possible connections busy, so wait until one becomes available.
try {
$this->awaitingConnection = new DeferredFuture;

$this->future = $this->awaitingConnection->getFuture();
// Connection will be pulled from $this->idle when future is resolved.
($this->future = $this->awaitingConnection->getFuture())->await();
$this->future->await();
} finally {
$this->awaitingConnection = null;
$this->future = null;
}
}
Expand All @@ -319,11 +319,7 @@ protected function push(SqlConnection $connection): void
{
\assert(isset($this->connections[$connection]), 'Connection is not part of this pool');

if ($connection->isClosed()) {
$this->connections->detach($connection);
} else {
$this->idle->enqueue($connection);
}
$this->idle->enqueue($connection);

$this->awaitingConnection?->complete($connection);
$this->awaitingConnection = null;
Expand Down

0 comments on commit 85449d5

Please sign in to comment.