From 12156d3beb8a16c0e2e8cf7180e1fbf27280a669 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sat, 9 Nov 2024 01:17:28 +0100 Subject: [PATCH] libstore: fix download thread notifications since 4ae6fb5a8f0d456b8d2ba2aaca3712b4e49057fc dropping a source of a download might not properly cancel the associated curl transfer after the transfer was paused. we have also not unpaused the transfer often enough, only if the transfer buffer had been drained in its entirety. Change-Id: Ic9298d9df71daa0f3d1c3fd718ed441edae9e863 --- src/libstore/filetransfer.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index ef914ddeb..8d7ccae87 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -808,7 +808,7 @@ struct curlFileTransfer : public FileTransfer bool done = false, failed = false; std::exception_ptr exc; std::string data; - std::condition_variable avail, request; + std::condition_variable avail; }; auto _state = std::make_shared>(); @@ -823,7 +823,6 @@ struct curlFileTransfer : public FileTransfer state->done = true; state->exc = ex; state->avail.notify_one(); - state->request.notify_one(); }, [_state](std::string_view data) { auto state(_state->lock()); @@ -872,7 +871,11 @@ struct curlFileTransfer : public FileTransfer // wake up the download thread if it's still going and have it abort auto state(_state->lock()); state->failed |= !state->done; - state->request.notify_one(); + try { + transfer->unpause(); + } catch (...) { + ignoreExceptionInDestructor(); + } } void awaitData(Sync::Lock & state) @@ -894,7 +897,7 @@ struct curlFileTransfer : public FileTransfer chunk = std::move(state->data); buffered = chunk; - state->request.notify_one(); + transfer->unpause(); } }