[http] don't retry when there's already a request in progress
This commit is contained in:
@@ -125,7 +125,6 @@ void HTTPNSURLRequest::start() {
|
||||
attempts++;
|
||||
|
||||
@autoreleasepool {
|
||||
|
||||
NSURL *url = [NSURL URLWithString:@(resource.url.c_str())];
|
||||
if (context->accountType == 0 &&
|
||||
([url.host isEqualToString:@"mapbox.com"] || [url.host hasSuffix:@".mapbox.com"])) {
|
||||
@@ -317,7 +316,7 @@ void HTTPNSURLRequest::retry(uint64_t timeout) {
|
||||
void HTTPNSURLRequest::retry() {
|
||||
// All batons get notified when the network status changed, but some of them
|
||||
// might not actually wait for the network to become available again.
|
||||
if (strategy == PreemptImmediately) {
|
||||
if (strategy == PreemptImmediately && !task) {
|
||||
// Triggers the timer upon the next event loop iteration.
|
||||
timer.stop();
|
||||
timer.start(0, 0, [this] { start(); });
|
||||
|
||||
52
test/storage/http_retry_network_status.cpp
Normal file
52
test/storage/http_retry_network_status.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "storage.hpp"
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/storage/network_status.hpp>
|
||||
|
||||
|
||||
// Test for https://github.com/mapbox/mapbox-gl-native/issues/2123
|
||||
//
|
||||
// A request is made. While the request is in progress, the network status changes. This should
|
||||
// trigger an immediate retry of all requests that are not in progress. This test makes sure that
|
||||
// we don't accidentally double-trigger the request.
|
||||
|
||||
TEST_F(Storage, HTTPNetworkStatusChange) {
|
||||
SCOPED_TEST(HTTPNetworkStatusChange)
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
DefaultFileSource fs(nullptr);
|
||||
|
||||
const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/delayed" };
|
||||
|
||||
// This request takes 200 milliseconds to answer.
|
||||
Request* req = fs.request(resource, uv_default_loop(), [&](const Response& res) {
|
||||
fs.cancel(req);
|
||||
EXPECT_EQ(Response::Successful, res.status);
|
||||
EXPECT_EQ(false, res.stale);
|
||||
ASSERT_TRUE(res.data.get());
|
||||
EXPECT_EQ("Response", *res.data);
|
||||
EXPECT_EQ(0, res.expires);
|
||||
EXPECT_EQ(0, res.modified);
|
||||
EXPECT_EQ("", res.etag);
|
||||
EXPECT_EQ("", res.message);
|
||||
HTTPNetworkStatusChange.finish();
|
||||
});
|
||||
|
||||
// After 50 milliseconds, we're going to trigger a NetworkStatus change.
|
||||
uv_timer_t reachableTimer;
|
||||
uv_timer_init(uv_default_loop(), &reachableTimer);
|
||||
uv_timer_start(&reachableTimer, [] (uv_timer_t*) {
|
||||
mbgl::NetworkStatus::Reachable();
|
||||
}, 50, 0);
|
||||
|
||||
// This timer will keep the loop alive to make sure we would be getting a response in caes the
|
||||
// network status change triggered another change (which it shouldn't).
|
||||
uv_timer_t delayTimer;
|
||||
uv_timer_init(uv_default_loop(), &delayTimer);
|
||||
uv_timer_start(&delayTimer, [] (uv_timer_t*) {}, 300, 0);
|
||||
|
||||
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
}
|
||||
@@ -84,6 +84,7 @@
|
||||
'storage/http_issue_1369.cpp',
|
||||
'storage/http_load.cpp',
|
||||
'storage/http_other_loop.cpp',
|
||||
'storage/http_retry_network_status.cpp',
|
||||
'storage/http_reading.cpp',
|
||||
'storage/http_timeout.cpp',
|
||||
|
||||
|
||||
Reference in New Issue
Block a user