Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: mark JoinHandle as UnwindSafe (#4414) #4418

Merged
merged 2 commits into from Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions tokio/src/runtime/task/join.rs
Expand Up @@ -3,6 +3,7 @@ use crate::runtime::task::RawTask;
use std::fmt;
use std::future::Future;
use std::marker::PhantomData;
use std::panic::{RefUnwindSafe, UnwindSafe};
use std::pin::Pin;
use std::task::{Context, Poll};

Expand Down Expand Up @@ -150,6 +151,9 @@ cfg_rt! {
unsafe impl<T: Send> Send for JoinHandle<T> {}
unsafe impl<T: Send> Sync for JoinHandle<T> {}

impl<T: Send> UnwindSafe for JoinHandle<T> {}
impl<T: Send> RefUnwindSafe for JoinHandle<T> {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should it not be unwind safe when T isn't Send?


impl<T> JoinHandle<T> {
pub(super) fn new(raw: RawTask) -> JoinHandle<T> {
JoinHandle {
Expand Down
16 changes: 16 additions & 0 deletions tokio/tests/net_types_unwind.rs → tokio/tests/unwindsafe.rs
Expand Up @@ -2,6 +2,22 @@
#![cfg(feature = "full")]

use std::panic::{RefUnwindSafe, UnwindSafe};
use tokio::task::spawn_blocking;

#[tokio::test]
async fn futures_are_unwind_safe() {
unwind_safe_future(|| async {
let _ = spawn_blocking(|| {}).await;
})
.await
}

async fn unwind_safe_future<F, Fut>(_: F)
where
F: FnOnce() -> Fut,
Fut: std::future::Future<Output = ()> + std::panic::UnwindSafe,
{
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a pretty convoluted way to test this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I altered it to test the actual change 🙂


#[test]
fn net_types_are_unwind_safe() {
Expand Down