From 7e3ee399a5aef46b9f924ed80ff08054db9a7cac Mon Sep 17 00:00:00 2001 From: Sadetdin EYILI Date: Wed, 3 Dec 2025 18:11:27 +0100 Subject: [PATCH] reset primary read replica connections when reseting registry fix: https://github.com/doctrine/DoctrineBundle/issues/2154 --- src/Registry.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Registry.php b/src/Registry.php index 51827a560..c995f1377 100644 --- a/src/Registry.php +++ b/src/Registry.php @@ -36,6 +36,9 @@ public function reset(): void foreach ($this->getManagerNames() as $managerName => $serviceId) { $this->resetOrClearManager($managerName, $serviceId); } + foreach ($this->getConnectionNames() as $connectionName => $serviceId) { + $this->resetPrimaryReadReplicaConnection($connectionName, $serviceId); + } } private function resetOrClearManager(string $managerName, string $serviceId): void @@ -73,4 +76,24 @@ private function resetOrClearManager(string $managerName, string $serviceId): vo $this->resetManager($managerName); } + + private function resetPrimaryReadReplicaConnection(string $connectionName, string $serviceId): void + { + if (! $this->container->initialized($serviceId)) { + return; + } + + $connection = $this->container->get($serviceId); + + assert($connection instanceof Connection); + + + if (! $connection instanceof PrimaryReadReplicaConnection) { + return; + } + + if (true === $connection->isConnectedToPrimary()) { + $connection->ensureConnectedToReplica(); + } + } }