Skip to content

Commit 8e5a9e6

Browse files
committed
fix: Do not skip reconnect if last check is unknown
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 <[email protected]>
1 parent 60711ea commit 8e5a9e6

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

lib/private/DB/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ public function rollBack() {
872872

873873
private function reconnectIfNeeded(): void {
874874
if (
875-
!isset($this->lastConnectionCheck[$this->getConnectionName()]) ||
875+
isset($this->lastConnectionCheck[$this->getConnectionName()]) &&
876876
time() <= $this->lastConnectionCheck[$this->getConnectionName()] + 30 ||
877877
$this->isTransactionActive()
878878
) {

0 commit comments

Comments
 (0)