mirror of
https://github.com/nextcloud/server.git
synced 2026-04-21 14:23:17 -04:00
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()];`60711ea4cf/lib/private/DB/Connection.php (L215-L221)60711ea4cf/lib/private/DB/Connection.php (L891-L893)2b6d7bf65f/doctrine/dbal/src/Connections/PrimaryReadReplicaConnection.php (L136-L139)Then, if the connection name ends up as being 'primary', the reconnect logic is skipped:60711ea4cf/lib/private/DB/Connection.php (L874-L880)Follow-up of https://github.com/nextcloud/server/pull/41819 Signed-off-by: Louis Chemineau <louis@chmn.me>
This commit is contained in:
parent
aef968456f
commit
8a2437927d
1 changed files with 2 additions and 2 deletions
|
|
@ -218,8 +218,6 @@ class Connection extends PrimaryReadReplicaConnection {
|
|||
return parent::connect();
|
||||
}
|
||||
|
||||
$this->lastConnectionCheck[$this->getConnectionName()] = time();
|
||||
|
||||
// Only trigger the event logger for the initial connect call
|
||||
$eventLogger = Server::get(IEventLogger::class);
|
||||
$eventLogger->start('connect:db', 'db connection opened');
|
||||
|
|
@ -227,6 +225,8 @@ class Connection extends PrimaryReadReplicaConnection {
|
|||
$status = parent::connect();
|
||||
$eventLogger->end('connect:db');
|
||||
|
||||
$this->lastConnectionCheck[$this->getConnectionName()] = time();
|
||||
|
||||
return $status;
|
||||
} catch (Exception $e) {
|
||||
// throw a new exception to prevent leaking info from the stacktrace
|
||||
|
|
|
|||
Loading…
Reference in a new issue