From 294ba1d3f84bcbe9b1073b25422a7791295a712b Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Mon, 15 May 2023 14:24:10 +0200 Subject: [PATCH 1/2] task: avoid going through a reference in `IdleNotifiedSet` --- tokio/src/util/idle_notified_set.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tokio/src/util/idle_notified_set.rs b/tokio/src/util/idle_notified_set.rs index ce8ff9e9a71..c5bc6619f83 100644 --- a/tokio/src/util/idle_notified_set.rs +++ b/tokio/src/util/idle_notified_set.rs @@ -421,7 +421,7 @@ impl Wake for ListEntry { // We move ourself to the notified list. let me = unsafe { // Safety: We just checked that we are in this particular list. - lock.idle.remove(NonNull::from(&**me)).unwrap() + lock.idle.remove(ListEntry::as_raw(me)).unwrap() }; lock.notified.push_front(me); From b1bfbfc197db6ce29b12d0f5f434aebd3356677f Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Mon, 15 May 2023 14:43:53 +0200 Subject: [PATCH 2/2] Add test --- tokio/src/util/idle_notified_set.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tokio/src/util/idle_notified_set.rs b/tokio/src/util/idle_notified_set.rs index c5bc6619f83..85a5292bf66 100644 --- a/tokio/src/util/idle_notified_set.rs +++ b/tokio/src/util/idle_notified_set.rs @@ -460,3 +460,22 @@ unsafe impl linked_list::Link for ListEntry { ListEntry::addr_of_pointers(target) } } + +#[cfg(test)] +mod tests { + use crate::runtime::Builder; + use crate::task::JoinSet; + + // A test that runs under miri. + // + // https://github.com/tokio-rs/tokio/pull/5693 + #[test] + fn join_set_test() { + let rt = Builder::new_current_thread().build().unwrap(); + + let mut set = JoinSet::new(); + set.spawn_on(futures::future::ready(()), rt.handle()); + + rt.block_on(set.join_next()).unwrap().unwrap(); + } +}