From 7879ddefe76b4c39bf4d557f692e53b1e8e72442 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Thu, 11 Apr 2024 18:27:14 +0800 Subject: [PATCH] Fix Miri error (Stacked Borrow violation) in the test code of the timer wheel --- src/common/timer_wheel.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/common/timer_wheel.rs b/src/common/timer_wheel.rs index 3f154fef..aa78affa 100644 --- a/src/common/timer_wheel.rs +++ b/src/common/timer_wheel.rs @@ -509,16 +509,21 @@ impl<'iter, K> Iterator for TimerEventsIter<'iter, K> { node.as_ref().element.unset_timer_node_in_deq_nodes(); return Some(TimerEvent::Expired(node)); } + // The cache entry has not expired. Reschedule it. let node_p = NonNull::new(Box::into_raw(node)).expect("Got a null ptr"); + + #[cfg(test)] + // Get the entry info before rescheduling (mutating) the node to + // avoid Stacked Borrows/Tree Borrows violations on `node_p`. + let entry_info = + TrioArc::clone(unsafe { node_p.as_ref() }.element.entry_info()); + match self.timer_wheel.schedule_existing_node(node_p) { - #[cfg(test)] - ReschedulingResult::Rescheduled => { - let entry_info = unsafe { node_p.as_ref() }.element.entry_info(); - return Some(TimerEvent::Rescheduled(TrioArc::clone(entry_info))); - } - #[cfg(not(test))] ReschedulingResult::Rescheduled => { + #[cfg(test)] + return Some(TimerEvent::Rescheduled(entry_info)); + #[cfg(not(test))] return Some(TimerEvent::Rescheduled(())); } ReschedulingResult::Removed(node) => {