summaryrefslogtreecommitdiffstats
path: root/tokio/tests
diff options
context:
space:
mode:
authorJohn-John Tedro <udoprog@tedro.se>2020-12-04 06:29:59 +0100
committerGitHub <noreply@github.com>2020-12-03 21:29:59 -0800
commita125ebd745f31098aa170cb1009ff0fe34508d37 (patch)
tree8dab5d17383a5f63f7554ec009cf6e1408c46d96 /tokio/tests
parent00500d1b35f00c68117d8f4e7320303e967e92e3 (diff)
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
Diffstat (limited to 'tokio/tests')
-rw-r--r--tokio/tests/task_abort.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/tokio/tests/task_abort.rs b/tokio/tests/task_abort.rs
new file mode 100644
index 00000000..e84f19c3
--- /dev/null
+++ b/tokio/tests/task_abort.rs
@@ -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;
+ });
+}