Skip to content

Commit b779fce

Browse files
committed
Remove connection form Context on close
1 parent b1cf275 commit b779fce

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/DbManager.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ protected function instance(array|string|null $name = null, bool $force = false)
6161
$pool->setConnectionCreator(function () use ($name) {
6262
return $this->createConnection($name);
6363
});
64-
$pool->setConnectionCloser(function ($connection) {
65-
$this->closeConnection($connection);
64+
$pool->setConnectionCloser(function ($connection) use ($name) {
65+
$this->closeConnection($connection, $name);
6666
});
6767
$pool->setHeartbeatChecker(function ($connection) {
6868
$this->heartbeat($connection);
@@ -126,9 +126,10 @@ private function getHeartbeatSql(string $type): string
126126
* Close connection.
127127
*
128128
* @param ConnectionInterface $connection
129+
* @param string|null $name Connection config name used for Context cache key.
129130
* @return void
130131
*/
131-
protected function closeConnection(ConnectionInterface $connection): void
132+
protected function closeConnection(ConnectionInterface $connection, ?string $name = null): void
132133
{
133134
$connection->close();
134135
$clearProperties = function () {
@@ -137,5 +138,10 @@ protected function closeConnection(ConnectionInterface $connection): void
137138
$this->builder = null;
138139
};
139140
$clearProperties->call($connection);
141+
142+
if ($name !== null) {
143+
$key = "think-orm.connections.$name";
144+
Context::set($key, null);
145+
}
140146
}
141147
}

0 commit comments

Comments
 (0)