Skip to content

Commit 8a24379

Browse files
artongebackportbot[bot]
authored andcommitted
fix: Initialize lastConnectionCheck after first connection
We are checking whether the DB connection is alive once every 30 seconds. But when we are lacking the last check time, we are skipping the check and reconnect logic. This is causing the reconnect logic to never fire in those cases. It seems to me that "those cases", are actually always the case, as upon initialization, we are not using the proper connection name to store the time. In the `connect()` logic, when `$this->_conn` is null, `$this->getConnectionName()` is returning `replica`, so `$this->lastConnectionCheck` will be equal to `['replica' => time()];` https://github.com/nextcloud/server/blob/60711ea4cfde6f53d0b18bcd7e166a34a43056a5/lib/private/DB/Connection.php#L215-L221 https://github.com/nextcloud/server/blob/60711ea4cfde6f53d0b18bcd7e166a34a43056a5/lib/private/DB/Connection.php#L891-L893 https://github.com/nextcloud/3rdparty/blob/2b6d7bf65ff242ea050e736925f752a38d8da220/doctrine/dbal/src/Connections/PrimaryReadReplicaConnection.php#L136-L139 Then, if the connection name ends up as being 'primary', the reconnect logic is skipped: https://github.com/nextcloud/server/blob/60711ea4cfde6f53d0b18bcd7e166a34a43056a5/lib/private/DB/Connection.php#L874-L880 Follow-up of #41819 Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent aef9684 commit 8a24379

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/private/DB/Connection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,15 @@ public function connect($connectionName = null) {
218218
return parent::connect();
219219
}
220220

221-
$this->lastConnectionCheck[$this->getConnectionName()] = time();
222-
223221
// Only trigger the event logger for the initial connect call
224222
$eventLogger = Server::get(IEventLogger::class);
225223
$eventLogger->start('connect:db', 'db connection opened');
226224
/** @psalm-suppress InternalMethod */
227225
$status = parent::connect();
228226
$eventLogger->end('connect:db');
229227

228+
$this->lastConnectionCheck[$this->getConnectionName()] = time();
229+
230230
return $status;
231231
} catch (Exception $e) {
232232
// throw a new exception to prevent leaking info from the stacktrace

0 commit comments

Comments
 (0)