mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-11 15:19:19 +02:00
threadpool: make Submit return Expected instead of throwing
Unlike exceptions, which can be ignored as they require extra try-catch blocks, returning expected errors forces callers to always handle submission failures. Not throwing an exception also fixes an unclean shutdown bug #34573 since we no longer throw when attempting to Submit() from the libevent callback http_request_cb().
This commit is contained in:
@@ -87,10 +87,10 @@ FUZZ_TARGET(threadpool, .init = setup_threadpool_test) EXCLUSIVE_LOCKS_REQUIRED(
|
||||
std::future<void> fut;
|
||||
if (will_throw) {
|
||||
expected_fail_tasks++;
|
||||
fut = g_pool.Submit(ThrowTask{});
|
||||
fut = *Assert(g_pool.Submit(ThrowTask{}));
|
||||
} else {
|
||||
expected_task_counter++;
|
||||
fut = g_pool.Submit(CounterTask{task_counter});
|
||||
fut = *Assert(g_pool.Submit(CounterTask{task_counter}));
|
||||
}
|
||||
|
||||
// If caller wants to wait immediately, consume the future here (safe).
|
||||
|
||||
Reference in New Issue
Block a user