Skip to content

Commit cd8f76e

Browse files
authored
Fixed db connection has already been bound to another coroutine when used in defer (#3082)
* Fixed db connection has already been bound to another coroutine when used in defer * Update CHANGELOG-2.1.md
1 parent 263122b commit cd8f76e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/DB.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ public function __call($name, $arguments)
5959
if (! $hasContextConnection) {
6060
if ($this->shouldUseSameConnection($name)) {
6161
// Should storage the connection to coroutine context, then use defer() to release the connection.
62-
Context::set($this->getContextKey(), $connection);
63-
defer(function () use ($connection) {
62+
Context::set($contextKey = $this->getContextKey(), $connection);
63+
defer(function () use ($connection, $contextKey) {
64+
Context::set($contextKey, null);
6465
$connection->release();
6566
});
6667
} else {

0 commit comments

Comments
 (0)