fix race between block initialization and receiver disconnection

This commit is contained in:
Ibraheem Ahmed 2024-02-26 13:53:35 -05:00 committed by GitHub
parent b79db437dc
commit 580b003edd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -547,7 +547,7 @@ fn discard_all_messages(&self) {
} }
let mut head = self.head.index.load(Ordering::Acquire); 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 we're going to be dropping messages we need to synchronize with initialization
if head >> SHIFT != tail >> SHIFT { if head >> SHIFT != tail >> SHIFT {
@ -588,8 +588,8 @@ fn discard_all_messages(&self) {
drop(Box::from_raw(block)); drop(Box::from_raw(block));
} }
} }
head &= !MARK_BIT; head &= !MARK_BIT;
self.head.block.store(ptr::null_mut(), Ordering::Release);
self.head.index.store(head, Ordering::Release); self.head.index.store(head, Ordering::Release);
} }