Skip to content

Commit

Permalink
Fix race between block initialization and receiver disconnection (#1084)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheemdev authored and taiki-e committed Feb 28, 2024
1 parent 9ed9021 commit 86b6bb8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crossbeam-channel/src/flavors/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ impl<T> Channel<T> {
}

let mut head = self.head.index.load(Ordering::Acquire);
let mut block = self.head.block.load(Ordering::Acquire);
let mut block = self.head.block.swap(ptr::null_mut(), Ordering::AcqRel);

// If we're going to be dropping messages we need to synchronize with initialization
if head >> SHIFT != tail >> SHIFT {
Expand All @@ -596,6 +596,7 @@ impl<T> Channel<T> {
block = self.head.block.load(Ordering::Acquire);
}
}

unsafe {
// Drop all messages between head and tail and deallocate the heap-allocated blocks.
while head >> SHIFT != tail >> SHIFT {
Expand Down Expand Up @@ -623,7 +624,6 @@ impl<T> Channel<T> {
}
}
head &= !MARK_BIT;
self.head.block.store(ptr::null_mut(), Ordering::Release);
self.head.index.store(head, Ordering::Release);
}

Expand Down

0 comments on commit 86b6bb8

Please sign in to comment.