Merge "libstore: abort all curl transfers on interrupt" into main

This commit is contained in:
jade 2024-11-19 05:03:47 +00:00 committed by Gerrit Code Review
commit f116608a20

View file

@ -515,13 +515,12 @@ struct curlFileTransfer : public FileTransfer
// loop with kj. until then curl will handle its timeouts internally. // loop with kj. until then curl will handle its timeouts internally.
int64_t timeoutMs = INT64_MAX; int64_t timeoutMs = INT64_MAX;
while (!quit) { while (true) {
checkInterrupt();
{ {
auto cancel = [&] { return std::move(state_.lock()->cancel); }(); auto cancel = [&] { return std::move(state_.lock()->cancel); }();
for (auto & [item, promise] : cancel) { for (auto & [item, promise] : cancel) {
curl_multi_remove_handle(curlm.get(), item->req.get()); curl_multi_remove_handle(curlm.get(), item->req.get());
items.erase(item->req.get());
promise.set_value(); promise.set_value();
} }
} }
@ -545,6 +544,12 @@ struct curlFileTransfer : public FileTransfer
} }
} }
// only exit when all transfers are done (which will happen through the
// progress callback issuing an abort in the case of user interruption)
if (items.empty() && quit) {
break;
}
/* Wait for activity, including wakeup events. */ /* Wait for activity, including wakeup events. */
mc = curl_multi_poll(curlm.get(), nullptr, 0, std::min<int64_t>(timeoutMs, INT_MAX), nullptr); mc = curl_multi_poll(curlm.get(), nullptr, 0, std::min<int64_t>(timeoutMs, INT_MAX), nullptr);
if (mc != CURLM_OK) if (mc != CURLM_OK)