diff --git a/core/Pool/Pool.php b/core/Pool/Pool.php index 6ac21216..9b1d4409 100644 --- a/core/Pool/Pool.php +++ b/core/Pool/Pool.php @@ -120,6 +120,7 @@ class Pool extends Component $channel = $this->getChannel($name); if (!$channel->isEmpty()) { $connection = $channel->pop(); + defer(fn() => $this->maxIdleQuantity($channel)); if ($this->checkCanUse($name, $connection)) { return $connection; } @@ -128,6 +129,20 @@ class Pool extends Component } + /** + * @param $channel + * @throws ConfigException + * @throws Exception + */ + private function maxIdleQuantity($channel): void + { + $minx = Config::get('databases.pool.min', 1); + if ($channel->length() > $minx) { + $this->pop($channel, $minx); + } + } + + /** * @param $name * @return bool