From c23735d43be36d31911dd2c832f36e5e6a6078a1 Mon Sep 17 00:00:00 2001 From: ADD-SP Date: Tue, 17 Feb 2026 21:50:26 -0800 Subject: [PATCH] runtime: fix TOCTOU issue when decreasing `num_idle_threads` (#7918) --- tokio/src/runtime/blocking/pool.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tokio/src/runtime/blocking/pool.rs b/tokio/src/runtime/blocking/pool.rs index d694a4ece..309348124 100644 --- a/tokio/src/runtime/blocking/pool.rs +++ b/tokio/src/runtime/blocking/pool.rs @@ -568,13 +568,13 @@ impl Inner { // Thread exit self.metrics.dec_num_threads(); - // num_idle should now be tracked exactly, panic + // `num_idle_threads` should now be tracked exactly, panic // with a descriptive message if it is not the // case. let prev_idle = self.metrics.dec_num_idle_threads(); - assert!( - prev_idle >= self.metrics.num_idle_threads(), - "num_idle_threads underflowed on thread exit" + assert_ne!( + prev_idle, 0, + "`num_idle_threads` underflowed on thread exit" ); if shared.shutdown && self.metrics.num_threads() == 0 {