Skip to content

Commit 42ceedd

Browse files
committed
fix: prevent active_handles underflow in ProofTaskManagerHandle
- Added a debug assertion to ensure active_handles does not underflow when dropping a ProofTaskManagerHandle. - Implemented metrics recording to flush before exit when the last handle is dropped, enhancing monitoring capabilities.
1 parent 0b18f64 commit 42ceedd

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

crates/trie/parallel/src/proof_task.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,19 @@ impl Drop for ProofTaskManagerHandle {
10291029
fn drop(&mut self) {
10301030
// Decrement the number of active handles.
10311031
// When the last handle is dropped, the channels are dropped and workers shut down.
1032-
self.active_handles.fetch_sub(1, Ordering::SeqCst);
1032+
// atomically grab the current handle count and decrement it for Drop.
1033+
let previous_handles = self.active_handles.fetch_sub(1, Ordering::SeqCst);
1034+
1035+
debug_assert_ne!(
1036+
previous_handles, 0,
1037+
"active_handles underflow in ProofTaskManagerHandle::drop"
1038+
);
1039+
1040+
#[cfg(feature = "metrics")]
1041+
if previous_handles == 1 {
1042+
// Flush metrics before exit.
1043+
self.metrics.record();
1044+
}
10331045
}
10341046
}
10351047

0 commit comments

Comments
 (0)