From 2bd70dd6442a9ad93043db45df98bedd1c5867c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 27 Apr 2021 18:41:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Abstracts/Pool.php | 3 ++- System/Pool/Connection.php | 10 +++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/System/Abstracts/Pool.php b/System/Abstracts/Pool.php index 34665bdb..f23926ba 100644 --- a/System/Abstracts/Pool.php +++ b/System/Abstracts/Pool.php @@ -192,7 +192,7 @@ abstract class Pool extends Component $this->creates = Timer::tick(1000, [$this, 'Heartbeat_detection']); } if (!Context::hasContext('create::client::ing::' . $name)) { - $this->push($name, $this->createClient($name, $callback)); + $this->_items[$name]->push($this->createClient($name, $callback)); Context::remove('create::client::ing::' . $name); } } @@ -298,6 +298,7 @@ abstract class Pool extends Component if (!$this->_items[$name]->isFull()) { $this->_items[$name]->push($client); } + $this->remove($name); } diff --git a/System/Pool/Connection.php b/System/Pool/Connection.php index f146be07..2abbf5f7 100644 --- a/System/Pool/Connection.php +++ b/System/Pool/Connection.php @@ -187,19 +187,15 @@ class Connection extends Pool public function release($coroutineName, $isMaster) { $coroutineName = $this->name('mysql', $coroutineName, $isMaster); - if (!$this->hasClient($coroutineName)) { - return; - } - -// $this->error('Worker ' . env('worker') . ' recover db client ' . $coroutineName . ' length ' . $this->size($coroutineName)); /** @var PDO $client */ - $client = Context::getContext($coroutineName); + if (!($client = Context::getContext($coroutineName)) instanceof PDO) { + return; + } if ($client->inTransaction()) { $client->commit(); } $this->push($coroutineName, $client); - $this->remove($coroutineName); $this->lastTime = time(); }