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

Make future::JoinHandle::abort actually cancel task #91

Open
bkragl opened this issue Dec 21, 2022 · 1 comment
Open

Make future::JoinHandle::abort actually cancel task #91

bkragl opened this issue Dec 21, 2022 · 1 comment

Comments

@bkragl
Copy link
Contributor

bkragl commented Dec 21, 2022

The implementation of abort in #87 as detaching the task does not seem right, because detached tasks may still continue to run. Consider the following test, which should not fail but currently does.

#[test]
fn join_handle_abort_bug() {
    check_dfs(
        || {
            let (sender, receiver) = futures::channel::oneshot::channel();
            let t = future::spawn({
                async move {
                    receiver.await.unwrap();
                    panic!("should not get here");
                }
            });
            t.abort();
            sender.send(()).unwrap();
            shuttle::thread::yield_now();
        },
        None,
    );
}

(The yield_now is needed because otherwise the main task would immediately finish, in which case also the execution finishes because there are no attached tasks left.)

We need a way to actually cancel a task, which drops its continuation and returns a JoinError indicating cancellation.

@jamesbornholt
Copy link
Member

abort is funny because it's best-effort and so non-deterministic when the task should stop. The current implementation doesn't do that. Maybe just always canceling the task immediately is a better default, but it can miss executions, in the same way our wait_timeout implementations can miss executions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants