libstore: remove our custom early timeout handling

curl handles timeouts internally when it acts as the main event loop. we
only need to wake up to add new transfers to the multi handle or restart
an existing transfer that has passed its restart wait time. periodically
waking up is not required for curl, and we don't need it any more either

Change-Id: Ic774e1d9519f807cda1a89694bc3ede75216f329
This commit is contained in:
eldritch horrors 2024-10-29 20:33:42 +01:00
parent 4ae6fb5a8f
commit beb193d1e2

View file

@ -591,7 +591,9 @@ struct curlFileTransfer : public FileTransfer
bool quit = false; bool quit = false;
std::chrono::steady_clock::time_point nextWakeup; // NOTE: we will need to use CURLMOPT_TIMERFUNCTION to integrate this
// loop with kj. until then curl will handle its timeouts internally.
int64_t timeoutMs = INT64_MAX;
while (!quit) { while (!quit) {
checkInterrupt(); checkInterrupt();
@ -616,18 +618,10 @@ struct curlFileTransfer : public FileTransfer
} }
/* Wait for activity, including wakeup events. */ /* Wait for activity, including wakeup events. */
long maxSleepTimeMs = items.empty() ? 10000 : 100; mc = curl_multi_poll(curlm, nullptr, 0, std::min<int64_t>(timeoutMs, INT_MAX), nullptr);
auto sleepTimeMs =
nextWakeup != std::chrono::steady_clock::time_point()
? std::max(0, (int) std::chrono::duration_cast<std::chrono::milliseconds>(nextWakeup - std::chrono::steady_clock::now()).count())
: maxSleepTimeMs;
vomit("download thread waiting for %d ms", sleepTimeMs);
mc = curl_multi_poll(curlm, nullptr, 0, sleepTimeMs, nullptr);
if (mc != CURLM_OK) if (mc != CURLM_OK)
throw nix::Error("unexpected error from curl_multi_poll(): %s", curl_multi_strerror(mc)); throw nix::Error("unexpected error from curl_multi_poll(): %s", curl_multi_strerror(mc));
nextWakeup = std::chrono::steady_clock::time_point();
/* Add new curl requests from the incoming requests queue, /* Add new curl requests from the incoming requests queue,
except for requests that are embargoed (waiting for a except for requests that are embargoed (waiting for a
retry timeout to expire). */ retry timeout to expire). */
@ -635,6 +629,8 @@ struct curlFileTransfer : public FileTransfer
std::vector<std::shared_ptr<TransferItem>> incoming; std::vector<std::shared_ptr<TransferItem>> incoming;
auto now = std::chrono::steady_clock::now(); auto now = std::chrono::steady_clock::now();
timeoutMs = INT64_MAX;
{ {
auto state(state_.lock()); auto state(state_.lock());
for (auto & item : state->unpause) { for (auto & item : state->unpause) {
@ -647,9 +643,9 @@ struct curlFileTransfer : public FileTransfer
incoming.push_back(item); incoming.push_back(item);
state->incoming.pop(); state->incoming.pop();
} else { } else {
if (nextWakeup == std::chrono::steady_clock::time_point() using namespace std::chrono;
|| item->embargo < nextWakeup) auto wait = duration_cast<milliseconds>(item->embargo - now);
nextWakeup = item->embargo; timeoutMs = std::min<int64_t>(timeoutMs, wait.count());
break; break;
} }
} }