Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] fix: Initialize lastConnectionCheck after first connection #51018

Merged
merged 1 commit into from
Feb 25, 2025

Conversation

backportbot[bot]
Copy link

@backportbot backportbot bot commented Feb 25, 2025

Backport of PR #50874

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]>
@backportbot backportbot bot added bug 3. to review Waiting for reviews php Pull requests that update Php code feature: database Database related DB labels Feb 25, 2025
@backportbot backportbot bot added this to the Nextcloud 29.0.13 milestone Feb 25, 2025
@come-nc come-nc merged commit 662492b into stable29 Feb 25, 2025
182 checks passed
@come-nc come-nc deleted the backport/50874/stable29 branch February 25, 2025 15:01
@blizzz blizzz mentioned this pull request Mar 4, 2025
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews bug feature: database Database related DB php Pull requests that update Php code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants