From 0e8b2954f450dc43306fe630ac710650d453b67d Mon Sep 17 00:00:00 2001 From: Alex Qyoun-ae <4062971+MazterQyou@users.noreply.github.com> Date: Tue, 27 May 2025 19:19:11 +0400 Subject: [PATCH] fix: Do not panic on underflow when shrinking memory usage tracker Signed-off-by: Alex Qyoun-ae <4062971+MazterQyou@users.noreply.github.com> --- .../core/src/execution/memory_manager.rs | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/datafusion/core/src/execution/memory_manager.rs b/datafusion/core/src/execution/memory_manager.rs index dcb539a0852c..885c89fbf3d7 100644 --- a/datafusion/core/src/execution/memory_manager.rs +++ b/datafusion/core/src/execution/memory_manager.rs @@ -288,21 +288,12 @@ impl MemoryManager { } pub(crate) fn shrink_tracker_usage(&self, delta: usize) { - let update = - self.trackers_total - .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| { - if x >= delta { - Some(x - delta) - } else { - None - } - }); - update.unwrap_or_else(|_| { - panic!( - "Tracker total memory shrink by {} underflow, current value is ", - delta - ) - }); + self.trackers_total + .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| { + // Do not panic, set to usize::MIN on underflow + Some(x.saturating_sub(delta)) + }) + .expect("Unexpected underflow in tracker memory usage"); } fn get_requester_total(&self) -> usize {