mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-14 17:57:57 -05:00
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.
This commit is contained in:
@@ -1029,7 +1029,19 @@ impl Drop for ProofTaskManagerHandle {
|
||||
fn drop(&mut self) {
|
||||
// Decrement the number of active handles.
|
||||
// When the last handle is dropped, the channels are dropped and workers shut down.
|
||||
self.active_handles.fetch_sub(1, Ordering::SeqCst);
|
||||
// atomically grab the current handle count and decrement it for Drop.
|
||||
let previous_handles = self.active_handles.fetch_sub(1, Ordering::SeqCst);
|
||||
|
||||
debug_assert_ne!(
|
||||
previous_handles, 0,
|
||||
"active_handles underflow in ProofTaskManagerHandle::drop"
|
||||
);
|
||||
|
||||
#[cfg(feature = "metrics")]
|
||||
if previous_handles == 1 {
|
||||
// Flush metrics before exit.
|
||||
self.metrics.record();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user