Skip to content

Commit

Permalink
task: fix stacked borrows issue in JoinSet (#5693)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn committed May 15, 2023
1 parent 70364b7 commit f6313f4
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tokio/src/util/idle_notified_set.rs
Expand Up @@ -421,7 +421,7 @@ impl<T: 'static> Wake for ListEntry<T> {
// 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);

Expand Down Expand Up @@ -460,3 +460,22 @@ unsafe impl<T> linked_list::Link for ListEntry<T> {
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();
}
}

0 comments on commit f6313f4

Please sign in to comment.