-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
fix: Initialize lastConnectionCheck after first connection #50874
Open
artonge
wants to merge
1
commit into
master
Choose a base branch
from
artonge/fix/login_flow_v2_sessions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8e5a9e6
to
cd5cdfd
Compare
Maybe move it down after the call to parent::connect? There getConnectionName should return the correct value, no? |
That makes sense indeed. |
cd5cdfd
to
10c0c78
Compare
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]>
10c0c78
to
066c92f
Compare
Confirmed to improve the situation in production. |
come-nc
approved these changes
Feb 20, 2025
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
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.
Investigation
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 returningreplica
, so$this->lastConnectionCheck
will be equal to['replica' => time()];
server/lib/private/DB/Connection.php
Lines 215 to 221 in 60711ea
server/lib/private/DB/Connection.php
Lines 891 to 893 in 60711ea
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:
server/lib/private/DB/Connection.php
Lines 874 to 880 in 60711ea
Other solution
Find a more reliable way to get the connection name.
Follow-up of #41819