Skip to content

Commit

Permalink
Properly handle ConnectionValidator error
Browse files Browse the repository at this point in the history
Properly handle errors during the update of the server settings.
Due to an unhandled result, the client could get stuck in a ` reconnecting` state.
  • Loading branch information
TheOneRing committed Jan 10, 2024
1 parent 1174782 commit 45f42a2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 44 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/11467
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Client stuck in `reconnecting`

Properly handle errors during the update of the server settings.
Due to an unhandled result, the client could get stuck in a ` reconnecting` state.

https://github.com/owncloud/client/pull/11467
31 changes: 24 additions & 7 deletions src/gui/connectionvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,30 @@ void ConnectionValidator::slotAuthSuccess()
const auto unsupportedServerError = [this] {
_errors.append({tr("The configured server for this client is too old."), tr("Please update to the latest server and restart the client.")});
};
connect(fetchSetting, &FetchServerSettingsJob::unknownServerDetected, unsupportedServerError);
connect(fetchSetting, &FetchServerSettingsJob::unsupportedServerDetected, [unsupportedServerError, this] {
unsupportedServerError();
reportResult(ServerVersionMismatch);
});

connect(fetchSetting, &FetchServerSettingsJob::finishedSignal, this, [this] { reportResult(Connected); });
connect(
fetchSetting, &FetchServerSettingsJob::finishedSignal, this, [fetchSetting, unsupportedServerError, this](FetchServerSettingsJob::Result result) {
switch (result) {
case FetchServerSettingsJob::Result::UnsupportedServer:
unsupportedServerError();
reportResult(ServerVersionMismatch);
break;
case FetchServerSettingsJob::Result::InvalidCredentials:
reportResult(CredentialsWrong);
break;
case FetchServerSettingsJob::Result::TimeOut:
reportResult(Timeout);
break;
case FetchServerSettingsJob::Result::Success:
if (_account->serverSupportLevel() == Account::ServerSupportLevel::Unknown) {
unsupportedServerError();
}
reportResult(Connected);
break;
case FetchServerSettingsJob::Result::Undefined:
reportResult(Undefined);
break;
}
});

fetchSetting->start();
return;
Expand Down
55 changes: 32 additions & 23 deletions src/gui/fetchserversettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,25 @@ void FetchServerSettingsJob::start()
_account->setHttp2Supported(reply->attribute(QNetworkRequest::Http2WasUsedAttribute).toBool());
}
_account->setCapabilities({_account->url(), caps.toVariantMap()});
if (checkServerInfo()) {
auto *userJob = new JsonApiJob(_account, QStringLiteral("ocs/v2.php/cloud/user"), SimpleNetworkJob::UrlQuery{}, QNetworkRequest{}, this);
userJob->setAuthenticationJob(isAuthJob());
userJob->setTimeout(timeoutC);
connect(userJob, &JsonApiJob::finishedSignal, this, [userJob, this] {
// We cannot deal with servers < 10.0.0
switch (_account->serverSupportLevel()) {
case Account::ServerSupportLevel::Unknown:
[[fallthrough]];
case Account::ServerSupportLevel::Supported:
break;
case Account::ServerSupportLevel::Unsupported:
Q_EMIT finishedSignal(Result::UnsupportedServer);
return;
}
auto *userJob = new JsonApiJob(_account, QStringLiteral("ocs/v2.php/cloud/user"), SimpleNetworkJob::UrlQuery{}, QNetworkRequest{}, this);
userJob->setAuthenticationJob(isAuthJob());
userJob->setTimeout(timeoutC);
connect(userJob, &JsonApiJob::finishedSignal, this, [userJob, this] {
if (userJob->timedOut()) {
Q_EMIT finishedSignal(Result::TimeOut);
} else if (userJob->httpStatusCode() == 401) {
Q_EMIT finishedSignal(Result::InvalidCredentials);
} else if (userJob->ocsSuccess()) {
const auto userData = userJob->data().value(QStringLiteral("ocs")).toObject().value(QStringLiteral("data")).toObject();
const QString user = userData.value(QStringLiteral("id")).toString();
if (!user.isEmpty()) {
Expand All @@ -72,9 +86,19 @@ void FetchServerSettingsJob::start()
_account->setDavDisplayName(displayName);
}
runAsyncUpdates();
Q_EMIT finishedSignal();
});
userJob->start();
Q_EMIT finishedSignal(Result::Success);
} else {
Q_EMIT finishedSignal(Result::Undefined);
}
});
userJob->start();
} else {
if (job->timedOut()) {
Q_EMIT finishedSignal(Result::TimeOut);
} else if (job->httpStatusCode() == 401) {
Q_EMIT finishedSignal(Result::InvalidCredentials);
} else {
Q_EMIT finishedSignal(Result::Undefined);
}
}
});
Expand Down Expand Up @@ -103,21 +127,6 @@ void FetchServerSettingsJob::runAsyncUpdates()
jsonJob->start();
}
}
bool FetchServerSettingsJob::checkServerInfo()
{
// We cannot deal with servers < 10.0.0
switch (_account->serverSupportLevel()) {
case Account::ServerSupportLevel::Supported:
break;
case Account::ServerSupportLevel::Unknown:
Q_EMIT unknownServerDetected();
break;
case Account::ServerSupportLevel::Unsupported:
Q_EMIT unsupportedServerDetected();
return false;
}
return true;
}

bool FetchServerSettingsJob::isAuthJob() const
{
Expand Down
17 changes: 3 additions & 14 deletions src/gui/fetchserversettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,21 @@ class FetchServerSettingsJob : public QObject
{
Q_OBJECT
public:
enum class Result { Success, TimeOut, InvalidCredentials, UnsupportedServer, Undefined };
Q_ENUM(Result);
FetchServerSettingsJob(const AccountPtr &account, QObject *parent);

void start();

Q_SIGNALS:
/***
* The version of the server is unsupported
*/
void unsupportedServerDetected();

/***
* We failed to detect the server version
*/
void unknownServerDetected();

void finishedSignal();
void finishedSignal(Result);

private:
void runAsyncUpdates();

bool checkServerInfo();

// returns whether the started jobs should be excluded from the retry queue
bool isAuthJob() const;


const AccountPtr _account;
};

Expand Down

0 comments on commit 45f42a2

Please sign in to comment.