Make `future::JoinHandle::abort` actually cancel task
- Dominant language
- Rust
- Stars
- 1.1k
- Forks
- 59
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 15
Description
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.
```rust
#[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.
Contributor guide
Research direction
Start at future::JoinHandle::abort and the future::spawn path, then run the supplied join_handle_abort_bug test under check_dfs. Done means abort drops the task continuation so sending on the oneshot cannot reach the panic, and the canceled join returns a JoinError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100