From ad3d4b73c3d7e485e93d59d8e8c9e12f8f62aad5 Mon Sep 17 00:00:00 2001 From: Morgan Gallant Date: Fri, 20 Feb 2026 16:36:14 +0100 Subject: [PATCH] re-check notified while holding state lock Signed-off-by: Morgan Gallant --- src/sync_placeholder.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/sync_placeholder.rs b/src/sync_placeholder.rs index de1c162..13ca6de 100644 --- a/src/sync_placeholder.rs +++ b/src/sync_placeholder.rs @@ -558,6 +558,20 @@ impl< let new_waker = cx.waker(); if !waker.will_wake(new_waker) { let mut state = shared.state.write(); + // Re-check notified after acquiring the lock. A concurrent + // insert may have drained the waiters list between the + // notified check in the match guard above and this point. + if this.notified.load(Ordering::Acquire) { + drop(state); + let JoinFutureState::Pending { shared, .. } = + mem::replace(&mut this.state, JoinFutureState::Done) + else { + unsafe { unreachable_unchecked() } + }; + return Poll::Ready(PlaceholderGuard::handle_notification( + lifecycle, shard, shared, + )); + } if let Some(w) = state .waiters .iter_mut()