From 9493e8f42ebf068bc7ac66a187636ca0ce708b8d Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 4 Jul 2017 12:23:23 +0200 Subject: [PATCH] AccountState: Add a 1-5min reconnection delay #5872 This only applies when the server was explicitly in maintenance mode or when it was 503-unavailable. --- src/gui/accountstate.cpp | 21 +++++++++++++++++++++ src/gui/accountstate.h | 21 +++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index e7ed89bc2..d2025dde1 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -20,6 +20,7 @@ #include "configfile.h" #include +#include #include namespace OCC { @@ -32,6 +33,7 @@ AccountState::AccountState(AccountPtr account) , _state(AccountState::Disconnected) , _connectionStatus(ConnectionValidator::Undefined) , _waitingForNewCredentials(false) + , _maintenanceToConnectedDelay(60000 + (qrand() % (4 * 60000))) // 1-5min delay { qRegisterMetaType("AccountState*"); @@ -228,6 +230,23 @@ void AccountState::slotConnectionValidatorResult(ConnectionValidator::Status sta return; } + // Come online gradually from 503 or maintenance mode + if (status == ConnectionValidator::Connected + && (_connectionStatus == ConnectionValidator::ServiceUnavailable + || _connectionStatus == ConnectionValidator::MaintenanceMode)) { + if (!_timeSinceMaintenanceOver.isValid()) { + qCInfo(lcAccountState) << "AccountState reconnection: delaying for" + << _maintenanceToConnectedDelay << "ms"; + _timeSinceMaintenanceOver.start(); + QTimer::singleShot(_maintenanceToConnectedDelay + 100, this, SLOT(checkConnectivity())); + return; + } else if (_timeSinceMaintenanceOver.elapsed() < _maintenanceToConnectedDelay) { + qCInfo(lcAccountState) << "AccountState reconnection: only" + << _timeSinceMaintenanceOver.elapsed() << "ms have passed"; + return; + } + } + if (_connectionStatus != status) { qCInfo(lcAccountState) << "AccountState connection status change: " << connectionStatusString(_connectionStatus) << "->" @@ -263,9 +282,11 @@ void AccountState::slotConnectionValidatorResult(ConnectionValidator::Status sta setState(SignedOut); break; case ConnectionValidator::ServiceUnavailable: + _timeSinceMaintenanceOver.invalidate(); setState(ServiceUnavailable); break; case ConnectionValidator::MaintenanceMode: + _timeSinceMaintenanceOver.invalidate(); setState(MaintenanceMode); break; case ConnectionValidator::Timeout: diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h index 450766bf8..2333bcece 100644 --- a/src/gui/accountstate.h +++ b/src/gui/accountstate.h @@ -107,10 +107,6 @@ public: bool isConnected() const; - /// Triggers a ping to the server to update state and - /// connection status and errors. - void checkConnectivity(); - /** Returns a new settings object for this account, already in the right groups. */ std::unique_ptr settings(); @@ -127,6 +123,11 @@ public: */ void tagLastSuccessfullETagRequest(); +public slots: + /// Triggers a ping to the server to update state and + /// connection status and errors. + void checkConnectivity(); + private: void setState(State state); @@ -148,6 +149,18 @@ private: bool _waitingForNewCredentials; QElapsedTimer _timeSinceLastETagCheck; QPointer _connectionValidator; + + /** + * Starts counting when the server starts being back up after 503 or + * maintenance mode. The account will only become connected once this + * timer exceeds the _maintenanceToConnectedDelay value. + */ + QElapsedTimer _timeSinceMaintenanceOver; + + /** + * Milliseconds for which to delay reconnection after 503/maintenance. + */ + int _maintenanceToConnectedDelay; }; }