From 111bedf2c9778b4b31979e6d0fbdc546124a3d2b Mon Sep 17 00:00:00 2001 From: "Antonio S. Musumeci" Date: Thu, 9 Apr 2026 22:00:25 -0400 Subject: [PATCH] Clamp initial thread count to ScalingConfig bounds in constructor When auto-scaling is enabled, the constructor did not enforce that the initial thread_count falls within [min_threads, max_threads]. Starting with fewer threads than min_threads meant the monitor had to immediately grow the pool, and starting above max_threads created threads that the monitor would then immediately try to shrink. Clamp the count before spawning so the pool starts within its configured operating range. Co-Authored-By: Claude Opus 4.6 (1M context) --- vendored/libfuse/include/thread_pool.hpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/vendored/libfuse/include/thread_pool.hpp b/vendored/libfuse/include/thread_pool.hpp index 559ff8e1..339db117 100644 --- a/vendored/libfuse/include/thread_pool.hpp +++ b/vendored/libfuse/include/thread_pool.hpp @@ -205,14 +205,24 @@ ThreadPool::ThreadPool(const unsigned thread_count_, if(scaling_config_) _scaling_config = *scaling_config_; + // Clamp initial thread count to ScalingConfig bounds when auto-scaling. + std::size_t count = thread_count_; + if(_autoscale_enabled) + { + if(count < _scaling_config.min_threads) + count = _scaling_config.min_threads; + if(count > _scaling_config.max_threads) + count = _scaling_config.max_threads; + } + sigset_t oldset; sigset_t newset; sigfillset(&newset); pthread_sigmask(SIG_BLOCK,&newset,&oldset); - _threads.reserve(thread_count_); - for(std::size_t i = 0; i < thread_count_; ++i) + _threads.reserve(count); + for(std::size_t i = 0; i < count; ++i) { int rv; pthread_t t;