From e7acf4e375360e24b616e3fd28b8deb5be6d3407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Fri, 21 Feb 2025 21:41:35 +0100 Subject: [PATCH] Add failing loom test showing bug Receiver::drop impl This test shows that Receiver::drop did not properly handle the UNPARKING state --- tests/loom.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/loom.rs b/tests/loom.rs index 4ce5f26..dccf7dd 100644 --- a/tests/loom.rs +++ b/tests/loom.rs @@ -98,6 +98,32 @@ fn send_then_poll() { }) } +// Make sure the receiver can be dropped while a send is happening in parallel +#[cfg(feature = "async")] +#[test] +fn poll_then_drop_receiver_during_send() { + loom::model(|| { + let (sender, mut receiver) = oneshot::channel::(); + + let (waker, _waker_handle) = helpers::waker::waker(); + let mut context = task::Context::from_waker(&waker); + + // Put the channel into the receiving state + assert_eq!(Pin::new(&mut receiver).poll(&mut context), Poll::Pending); + + // Spawn a separate thread that sends in parallel + let t = thread::spawn(move || { + let _ = sender.send(1234); + }); + + // Drop the receiver. Loom will make sure all thread interleavings with the send are tested + drop(receiver); + + // The send operation should also not have panicked + t.join().unwrap(); + }) +} + #[cfg(feature = "async")] #[test] fn poll_then_send() {