From aeb31eeface45e4a1c07e956e78cea0d0a5927ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 27 Apr 2021 14:00:20 +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 | 8 ++++++-- System/Pool/Connection.php | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/System/Abstracts/Pool.php b/System/Abstracts/Pool.php index 98cf8478..0dde27f9 100644 --- a/System/Abstracts/Pool.php +++ b/System/Abstracts/Pool.php @@ -170,8 +170,9 @@ abstract class Pool extends Component } $time = microtime(true); if (!$this->hasItem($name)) { - $this->createByCallback($name, $callback); + return $this->createByCallback($name, $callback); } + $connection = $this->_items[$name]->pop(0.01); if (microtime(true) - $time >= 0.007) { $this->warning('Worker #' . env('worker') . ' get client use time ' . (microtime(true) - $time)); @@ -187,14 +188,17 @@ abstract class Pool extends Component /** * @param $name * @param mixed $callback + * @return mixed * @throws Exception */ - private function createByCallback($name, mixed $callback) + private function createByCallback($name, mixed $callback): mixed { if ($this->creates === -1 && !is_callable($callback)) { $this->creates = Timer::tick(1000, [$this, 'Heartbeat_detection']); } + return $this->createClient($name, $callback); + if (!Context::hasContext('create::client::ing::' . $name)) { $this->push($name, $this->createClient($name, $callback)); Context::remove('create::client::ing::' . $name); diff --git a/System/Pool/Connection.php b/System/Pool/Connection.php index ef1f6048..764bdcde 100644 --- a/System/Pool/Connection.php +++ b/System/Pool/Connection.php @@ -182,6 +182,7 @@ class Connection extends Pool /** * @param $coroutineName * @param $isMaster + * @throws Exception */ public function release($coroutineName, $isMaster) { @@ -190,6 +191,8 @@ class Connection extends Pool return; } + $this->error('recover db client ' . $coroutineName); + /** @var PDO $client */ $client = Context::getContext($coroutineName); if ($client->inTransaction()) { @@ -241,7 +244,7 @@ class Connection extends Pool try { if (empty($client) || !($client instanceof PDO)) { $result = false; - } else { + } else { $result = true; } } catch (Error | Throwable $exception) {