-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rt: fix panic in task abort when off rt (#3159)
A call to `JoinHandle::abort` releases a task. When called from outside of the runtime, this panics due to the current implementation checking for a thread-local worker context. This change makes accessing the thread-local context optional under release, by falling back to remotely marking a task remotely as dropped. Behaving the same as if the core was stolen by another worker. Fixes #3157
- Loading branch information
Showing
2 changed files
with
83 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#![warn(rust_2018_idioms)] | ||
#![cfg(feature = "full")] | ||
|
||
/// Checks that a suspended task can be aborted without panicking as reported in | ||
/// issue #3157: <https://github.com/tokio-rs/tokio/issues/3157>. | ||
#[test] | ||
fn test_abort_without_panic_3157() { | ||
let rt = tokio::runtime::Builder::new_multi_thread() | ||
.enable_time() | ||
.worker_threads(1) | ||
.build() | ||
.unwrap(); | ||
|
||
rt.block_on(async move { | ||
let handle = tokio::spawn(async move { | ||
println!("task started"); | ||
tokio::time::sleep(std::time::Duration::new(100, 0)).await | ||
}); | ||
|
||
// wait for task to sleep. | ||
tokio::time::sleep(std::time::Duration::new(1, 0)).await; | ||
|
||
handle.abort(); | ||
let _ = handle.await; | ||
}); | ||
} |