From 7834fdd471bd4e4f866372b2577105998d32e643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=93=AD=E6=98=95?= <715557344@qq.com> Date: Wed, 13 Mar 2019 11:56:46 +0800 Subject: [PATCH] Defer release must in coroutine environment. --- src/db-connection/src/ConnectionResolver.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/db-connection/src/ConnectionResolver.php b/src/db-connection/src/ConnectionResolver.php index 88cc8e639..a52449ea3 100644 --- a/src/db-connection/src/ConnectionResolver.php +++ b/src/db-connection/src/ConnectionResolver.php @@ -16,6 +16,7 @@ use Hyperf\Database\ConnectionInterface; use Hyperf\Database\ConnectionResolverInterface; use Hyperf\DbConnection\Pool\PoolFactory; use Hyperf\Utils\Context; +use Hyperf\Utils\Coroutine; use Psr\Container\ContainerInterface; class ConnectionResolver implements ConnectionResolverInterface @@ -65,9 +66,11 @@ class ConnectionResolver implements ConnectionResolverInterface $pool = $this->factory->getPool($name); $connection = $pool->get()->getConnection(); Context::set($id, $connection); - defer(function () use ($connection) { - $connection->release(); - }); + if (Coroutine::inCoroutine()) { + defer(function () use ($connection) { + $connection->release(); + }); + } } return $connection;