diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-02-21 16:08:02 +0200 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-02-26 03:20:51 +0200 |
commit | 843cad04fbc0af614289a38b8846935ae2633943 (patch) | |
tree | ed2efe2b610671091496cd5a6d08770797c4d924 /platform/default/online_file_source.cpp | |
parent | e5e1fa81393bc53daa79ca60c001c7462095215c (diff) | |
download | qtlocation-mapboxgl-843cad04fbc0af614289a38b8846935ae2633943.tar.gz |
[core] Add retry delay on expired tiles
When we receive an expired tile, we don't immediately retry
because in case the server keeps serving an expired tile, that
would cause an infinite retry cycle.
Now we add an exponential delay, similarly to what we do for
connection errors.
Diffstat (limited to 'platform/default/online_file_source.cpp')
-rw-r--r-- | platform/default/online_file_source.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp index 367777d623..bfbf423af7 100644 --- a/platform/default/online_file_source.cpp +++ b/platform/default/online_file_source.cpp @@ -38,6 +38,11 @@ public: util::Timer timer; Callback callback; + // Counts the number of times a response was already expired when received. We're using + // this to add a delay when making a new request so we don't keep retrying immediately + // in case of a server serving expired tiles. + uint32_t expiredRequests = 0; + // Counts the number of subsequent failed requests. We're using this value for exponential // backoff when retrying requests. uint32_t failedRequests = 0; @@ -223,8 +228,10 @@ static Duration errorRetryTimeout(Response::Error::Reason failedRequestReason, u } } -static Duration expirationTimeout(optional<SystemTimePoint> expires) { - if (expires) { +static Duration expirationTimeout(optional<SystemTimePoint> expires, uint32_t expiredRequests) { + if (expiredRequests) { + return Seconds(1 << std::min(expiredRequests - 1, 31u)); + } else if (expires) { return std::max(SystemDuration::zero(), *expires - SystemClock::now()); } else { return Duration::max(); @@ -242,7 +249,7 @@ void OnlineFileRequestImpl::schedule(OnlineFileSource::Impl& impl, bool forceImm Duration timeout = forceImmediate ? Duration::zero() : std::min(errorRetryTimeout(failedRequestReason, failedRequests), - expirationTimeout(resource.priorExpires)); + expirationTimeout(resource.priorExpires, expiredRequests)); if (timeout == Duration::max()) { return; @@ -269,6 +276,12 @@ void OnlineFileRequestImpl::completed(OnlineFileSource::Impl& impl, Response res resource.priorExpires = response.expires; } + if (response.expires && response.expires < SystemClock::now()) { + expiredRequests++; + } else { + expiredRequests = 0; + } + if (!response.etag) { response.etag = resource.priorEtag; } else { |