From f9e36b38894823ae95190d64cd62bf4d71b185f8 Mon Sep 17 00:00:00 2001 From: "Antonio S. Musumeci" Date: Fri, 10 Apr 2026 16:44:18 -0400 Subject: [PATCH] thread_pool: replace assert with runtime check in enqueue_work_autoscale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The assert guarding against BoundedQueue::try_enqueue moving the callable on failure is compiled out in release builds (-DNDEBUG). If the queue implementation ever changed to move-from on failure, the empty Func would be enqueued as a poison pill, silently causing a worker thread to exit — a subtle, hard-to-diagnose pool corruption. Replace both assert() calls with a std::logic_error throw that remains active in all build configurations. This makes the invariant violation immediately visible rather than silently dangerous. Also remove the now-unused include. Co-Authored-By: Claude Opus 4.6 (1M context) --- vendored/libfuse/include/thread_pool.hpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/vendored/libfuse/include/thread_pool.hpp b/vendored/libfuse/include/thread_pool.hpp index 00c915aa..8b9ba024 100644 --- a/vendored/libfuse/include/thread_pool.hpp +++ b/vendored/libfuse/include/thread_pool.hpp @@ -24,7 +24,6 @@ #include "mutex.hpp" #include -#include #include #include #include @@ -1042,8 +1041,12 @@ ThreadPool::enqueue_work_autoscale(ThreadPool::PToken &ptok_, return; } - assert(static_cast(f) && - "BoundedQueue::try_enqueue moved the callable despite returning false"); + // If try_enqueue moved the callable despite returning false, the + // Func is empty and would act as a poison pill — re-enqueuing it + // could cause a worker to exit. Throw so the caller notices + // immediately rather than silently corrupting the pool. + if(!static_cast(f)) + throw std::logic_error("BoundedQueue::try_enqueue moved the callable despite returning false"); _maybe_grow_on_pressure(); @@ -1067,8 +1070,8 @@ ThreadPool::enqueue_work_autoscale(FuncType &&func_) return; } - assert(static_cast(f) && - "BoundedQueue::try_enqueue moved the callable despite returning false"); + if(!static_cast(f)) + throw std::logic_error("BoundedQueue::try_enqueue moved the callable despite returning false"); _maybe_grow_on_pressure();