diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index b6f482dbe7..178c5dd778 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -514,8 +514,17 @@ void Resource::init() { } } +const int MAX_ATTEMPTS = 8; + void Resource::attemptRequest() { _startedLoading = true; + + auto timer = qobject_cast(sender()); + if (timer) { + qCDebug(networking).nospace() << "Server unavailable for" << _url + << "- retrying asset load after" << timer->interval() << "ms - attempt" << _attempts << " of " << MAX_ATTEMPTS; + } + ResourceCache::attemptRequest(_self); } @@ -602,13 +611,10 @@ void Resource::handleReplyFinished() { } case ResourceRequest::Result::ServerUnavailable: { // retry with increasing delays - const int MAX_ATTEMPTS = 8; const int BASE_DELAY_MS = 1000; if (_attempts++ < MAX_ATTEMPTS) { auto waitTime = BASE_DELAY_MS * (int)pow(2.0, _attempts); - qCDebug(networking) << "Server unavailable for" << _url << - "retrying in " << waitTime << "ms," << - "attempt " << _attempts + 1 << "of" << MAX_ATTEMPTS; + QTimer::singleShot(waitTime, this, &Resource::attemptRequest); break; }