Skip to content

Commit

Permalink
HttpBinaryCacheStore::getFile(): Fix uncaught exception
Browse files Browse the repository at this point in the history
This method is marked as `noexcept`, but `enqueueFileTransfer()` can
throw `Interrupted` if the user has hit Ctrl-C or if the `ThreadPool`
that the thread is a part of is shutting down.
  • Loading branch information
edolstra committed Sep 26, 2024
1 parent 0ed67e5 commit 4566854
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/libstore/http-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,28 +169,29 @@ class HttpBinaryCacheStore : public virtual HttpBinaryCacheStoreConfig, public v
{
try {
checkEnabled();

auto request(makeRequest(path));

auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));

getFileTransfer()->enqueueFileTransfer(request,
{[callbackPtr, this](std::future<FileTransferResult> result) {
try {
(*callbackPtr)(std::move(result.get().data));
} catch (FileTransferError & e) {
if (e.error == FileTransfer::NotFound || e.error == FileTransfer::Forbidden)
return (*callbackPtr)({});
maybeDisable();
callbackPtr->rethrow();
} catch (...) {
callbackPtr->rethrow();
}
}});

} catch (...) {
callback.rethrow();
return;
}

auto request(makeRequest(path));

auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));

getFileTransfer()->enqueueFileTransfer(request,
{[callbackPtr, this](std::future<FileTransferResult> result) {
try {
(*callbackPtr)(std::move(result.get().data));
} catch (FileTransferError & e) {
if (e.error == FileTransfer::NotFound || e.error == FileTransfer::Forbidden)
return (*callbackPtr)({});
maybeDisable();
callbackPtr->rethrow();
} catch (...) {
callbackPtr->rethrow();
}
}});
}

/**
Expand Down

0 comments on commit 4566854

Please sign in to comment.