Skip to content

Commit 22a29f0

Browse files
committed
Do not retry http requests if we are shutting down
1 parent c425acd commit 22a29f0

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

http.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,15 +411,23 @@ namespace BinaryNinja::Http
411411
LogDebug("* Error: %s", instance->GetError().c_str());
412412
}
413413

414-
// Request failed, grab its error and try again
414+
// Request failed, grab its error and try again unless we're shutting down
415415
response.error = instance->GetError();
416-
if (retry == HTTP_MAX_RETRIES || context.cancelled)
416+
if (retry == HTTP_MAX_RETRIES || context.cancelled || BNIsShutdownRequested())
417417
break;
418418
size_t backoff = 1000 * HTTP_BACKOFF_FACTOR * (2 * pow(2, retry - 1));
419419
retry += 1;
420420
LogWarn("Attempt %d to %s %s failed, trying again in %zums\n", retry, request.m_method.data(),
421421
request.m_url.data(), backoff);
422-
std::this_thread::sleep_for(std::chrono::milliseconds(backoff));
422+
423+
// Wait in blocks of 100ms so we can check for shutdown
424+
for (size_t currentWait = 0; currentWait < backoff; currentWait += 100)
425+
{
426+
// If we're shutting down, return the error result instead of waiting to retry
427+
if (BNIsShutdownRequested())
428+
return result;
429+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
430+
}
423431
}
424432

425433
if (getenv("BN_DEBUG_HTTP"))

0 commit comments

Comments
 (0)