From 78d320a64cf6af1394e05a9a88192e6923c0f90e Mon Sep 17 00:00:00 2001 From: "Antonio S. Musumeci" Date: Fri, 10 Apr 2026 00:58:16 -0400 Subject: [PATCH] Clamp set_threads to autoscale bounds set_threads did not enforce ScalingConfig::min_threads / max_threads, so a caller could push the pool outside the range that the monitor thread and idle self-exit logic expect. For example, set_threads(1) with min_threads=2 would be rejected by _remove_thread_scaling_locked partway through, leaving the pool in a partially-shrunk state. Growing above max_threads had no guard at all. Clamp the requested count to [min_threads, max_threads] when autoscaling is enabled, mirroring the constructor's clamping logic. Co-Authored-By: Claude Opus 4.6 (1M context) --- vendored/libfuse/include/thread_pool.hpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/vendored/libfuse/include/thread_pool.hpp b/vendored/libfuse/include/thread_pool.hpp index 3b38d19d..cd6ea21a 100644 --- a/vendored/libfuse/include/thread_pool.hpp +++ b/vendored/libfuse/include/thread_pool.hpp @@ -777,6 +777,17 @@ ThreadPool::set_threads(const std::size_t count_) if(count_ == 0) return -EINVAL; + // Clamp to autoscale bounds so external callers can't push the + // pool outside the range the monitor and idle-exit logic expect. + std::size_t count = 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; + } + std::size_t current; { @@ -786,14 +797,14 @@ ThreadPool::set_threads(const std::size_t count_) int rv = 0; - for(std::size_t i = current; i < count_; ++i) + for(std::size_t i = current; i < count; ++i) { rv = _add_thread_scaling_locked({}); if(rv != 0) return rv; } - for(std::size_t i = count_; i < current; ++i) + for(std::size_t i = count; i < current; ++i) { rv = _remove_thread_scaling_locked(); if(rv != 0)