runtime: fix TOCTOU issue when decreasing num_idle_threads (#7918)

This commit is contained in:
ADD-SP
2026-02-17 21:50:26 -08:00
committed by GitHub
parent d83921bc51
commit c23735d43b
+4 -4
View File
@@ -568,13 +568,13 @@ impl Inner {
// Thread exit // Thread exit
self.metrics.dec_num_threads(); 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 // with a descriptive message if it is not the
// case. // case.
let prev_idle = self.metrics.dec_num_idle_threads(); let prev_idle = self.metrics.dec_num_idle_threads();
assert!( assert_ne!(
prev_idle >= self.metrics.num_idle_threads(), prev_idle, 0,
"num_idle_threads underflowed on thread exit" "`num_idle_threads` underflowed on thread exit"
); );
if shared.shutdown && self.metrics.num_threads() == 0 { if shared.shutdown && self.metrics.num_threads() == 0 {