summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--http.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/http.cpp b/http.cpp
index 6292f952..ed861f8d 100644
--- a/http.cpp
+++ b/http.cpp
@@ -411,15 +411,23 @@ namespace BinaryNinja::Http
LogDebug("* Error: %s", instance->GetError().c_str());
}
- // Request failed, grab its error and try again
+ // Request failed, grab its error and try again unless we're shutting down
response.error = instance->GetError();
- if (retry == HTTP_MAX_RETRIES || context.cancelled)
+ if (retry == HTTP_MAX_RETRIES || context.cancelled || BNIsShutdownRequested())
break;
size_t backoff = 1000 * HTTP_BACKOFF_FACTOR * (2 * pow(2, retry - 1));
retry += 1;
LogWarn("Attempt %d to %s %s failed, trying again in %zums\n", retry, request.m_method.data(),
request.m_url.data(), backoff);
- std::this_thread::sleep_for(std::chrono::milliseconds(backoff));
+
+ // Wait in blocks of 100ms so we can check for shutdown
+ for (size_t currentWait = 0; currentWait < backoff; currentWait += 100)
+ {
+ // If we're shutting down, return the error result instead of waiting to retry
+ if (BNIsShutdownRequested())
+ return result;
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ }
}
if (getenv("BN_DEBUG_HTTP"))