From 4434e3ba62307befe74806d4d70ae0718921c0d4 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Sat, 21 Nov 2026 18:12:38 -0500 Subject: [PATCH] fix: saturate the process thread queue depth instead of overflowing - process-thread-queue-depth is multiplied by the process thread count. A large depth overflowed the int, e.g. process-thread-queue-depth=1073741824 with 2 process threads, which is undefined behaviour. - Cap the product at INT_MAX. The queue only counts free slots, so a depth that large is unbounded in practice, as asked for. --- mkdocs/docs/config/threads.md | 6 +++--- vendored/libfuse/lib/fuse_loop.cpp | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/mkdocs/docs/config/threads.md b/mkdocs/docs/config/threads.md index 917612e2..b3239600 100644 --- a/mkdocs/docs/config/threads.md +++ b/mkdocs/docs/config/threads.md @@ -61,8 +61,8 @@ in the pool. * `process-thread-queue-depth=N` where `N>0`: Sets the number of outstanding requests that the process thread pool can have to `N * - process-thread-count`. If requests come in faster than can be - processed and the max queue depth hit then queuing the request will - block in order to limit memory growth. + process-thread-count`, at most 2147483647. If requests come in + faster than can be processed and the max queue depth hit then + queuing the request will block in order to limit memory growth. * `process-thread-queue-depth<=0`: Sets the queue depth to 2. May be used in the future to set dynamically. diff --git a/vendored/libfuse/lib/fuse_loop.cpp b/vendored/libfuse/lib/fuse_loop.cpp index 37998813..b28f535f 100644 --- a/vendored/libfuse/lib/fuse_loop.cpp +++ b/vendored/libfuse/lib/fuse_loop.cpp @@ -17,6 +17,7 @@ #include "fuse_msgbuf.hpp" #include +#include #include #include @@ -270,7 +271,13 @@ _calculate_thread_counts(int *read_thread_count_, if(*process_thread_queue_depth_ <= 0) *process_thread_queue_depth_ = 2; - *process_thread_queue_depth_ *= std::abs(*process_thread_count_); + // Saturate rather than overflow. A total this large is unbounded in + // practice anyway since the queue only counts free slots. + if(*process_thread_queue_depth_ > + (std::numeric_limits::max() / std::abs(*process_thread_count_))) + *process_thread_queue_depth_ = std::numeric_limits::max(); + else + *process_thread_queue_depth_ *= std::abs(*process_thread_count_); } int