From d88663890261c2c276cd76576655b137a8758670 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 4 Aug 2020 13:32:57 +0200 Subject: BaseJob: go for a retry on IncorrectResponse The most frequent occurence of IncorrectResponse so far is a proxy/CDN failure. This is not a grave error; there's a chance that the retry will succeed. In the worst case the job will fail after 3 identical errors (except SyncJob that will try to get through forever - but SyncJob failures should still be indicated in the client's UI in some non-intrusive way). --- lib/jobs/basejob.cpp | 55 +++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 24 deletions(-) (limited to 'lib/jobs') diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp index d6d48d2f..1f0e84ba 100644 --- a/lib/jobs/basejob.cpp +++ b/lib/jobs/basejob.cpp @@ -586,33 +586,40 @@ void BaseJob::stop() void BaseJob::finishJob() { stop(); - if (error() == TooManyRequests) { + switch(error()) { + case TooManyRequests: emit rateLimited(); d->connection->submit(this); return; - } - if (error() == Unauthorised && !d->needsToken - && !d->connection->accessToken().isEmpty()) { - // Rerun with access token (extension of the spec while - // https://github.com/matrix-org/matrix-doc/issues/701 is pending) - d->connection->setNeedsToken(objectName()); - qCWarning(d->logCat) << this << "re-running with authentication"; - emit retryScheduled(d->retriesTaken, 0); - d->connection->submit(this); - return; - } - if ((error() == NetworkError || error() == Timeout) - && d->retriesTaken < d->maxRetries) { - // TODO: The whole retrying thing should be put to Connection(Manager) - // otherwise independently retrying jobs make a bit of notification - // storm towards the UI. - const seconds retryIn = error() == Timeout ? 0s : getNextRetryInterval(); - ++d->retriesTaken; - qCWarning(d->logCat).nospace() << this << ": retry #" << d->retriesTaken - << " in " << retryIn.count() << " s"; - d->retryTimer.start(retryIn); - emit retryScheduled(d->retriesTaken, milliseconds(retryIn).count()); - return; + case Unauthorised: + if (!d->needsToken && !d->connection->accessToken().isEmpty()) { + // Rerun with access token (extension of the spec while + // https://github.com/matrix-org/matrix-doc/issues/701 is pending) + d->connection->setNeedsToken(objectName()); + qCWarning(d->logCat) << this << "re-running with authentication"; + emit retryScheduled(d->retriesTaken, 0); + d->connection->submit(this); + return; + } + break; + case NetworkError: + case IncorrectResponse: + case Timeout: + if (d->retriesTaken < d->maxRetries) { + // TODO: The whole retrying thing should be put to + // Connection(Manager) otherwise independently retrying jobs make a + // bit of notification storm towards the UI. + const seconds retryIn = error() == Timeout ? 0s + : getNextRetryInterval(); + ++d->retriesTaken; + qCWarning(d->logCat).nospace() + << this << ": retry #" << d->retriesTaken << " in " + << retryIn.count() << " s"; + d->retryTimer.start(retryIn); + emit retryScheduled(d->retriesTaken, milliseconds(retryIn).count()); + return; + } + default:; } Q_ASSERT(status().code != Pending); -- cgit v1.2.3