From d1bcde3753eeb347b582046294bdb772d8b2fdc8 Mon Sep 17 00:00:00 2001 From: "Antonio S. Musumeci" Date: Fri, 10 Apr 2026 14:18:02 -0400 Subject: [PATCH] Fix thread pool shutdown race Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- vendored/libfuse/include/thread_pool.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/vendored/libfuse/include/thread_pool.hpp b/vendored/libfuse/include/thread_pool.hpp index 5b331861..53749f33 100644 --- a/vendored/libfuse/include/thread_pool.hpp +++ b/vendored/libfuse/include/thread_pool.hpp @@ -686,12 +686,13 @@ inline void ThreadPool::_remove_self(pthread_t t_) { - // During shutdown the destructor owns all joins; don't detach. + mutex_lockguard(_threads_mutex); + + // Check _stop under the lock so the destructor can't snapshot this + // thread for joining and then race with us detaching ourselves. if(_stop.load(std::memory_order_acquire)) return; - mutex_lockguard(_threads_mutex); - auto it = std::find(_threads.begin(),_threads.end(),t_); if(it != _threads.end()) {