summaryrefslogtreecommitdiffstats
path: root/tokio/src/task/local.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tokio/src/task/local.rs')
-rw-r--r--tokio/src/task/local.rs33
1 files changed, 31 insertions, 2 deletions
diff --git a/tokio/src/task/local.rs b/tokio/src/task/local.rs
index cb62bd5e..6d0adf31 100644
--- a/tokio/src/task/local.rs
+++ b/tokio/src/task/local.rs
@@ -345,8 +345,9 @@ impl Schedule for Scheduler {
}
}
- fn release(&self, _: Task<Self>) {
- unreachable!("tasks should only be completed locally")
+ fn release(&self, task: Task<Self>) {
+ // This will be called when dropping the local runtime.
+ self.pending_drop.push(task);
}
fn release_local(&self, task: &Task<Self>) {
@@ -724,4 +725,32 @@ mod tests {
join2.await.unwrap()
});
}
+ #[test]
+ fn drop_cancels_tasks() {
+ // This test reproduces issue #1842
+ use crate::sync::oneshot;
+ use std::time::Duration;
+
+ let mut rt = runtime::Builder::new()
+ .enable_time()
+ .basic_scheduler()
+ .build()
+ .unwrap();
+
+ let (started_tx, started_rx) = oneshot::channel();
+
+ let local = LocalSet::new();
+ local.spawn_local(async move {
+ started_tx.send(()).unwrap();
+ loop {
+ crate::time::delay_for(Duration::from_secs(3600)).await;
+ }
+ });
+
+ local.block_on(&mut rt, async {
+ started_rx.await.unwrap();
+ });
+ drop(local);
+ drop(rt);
+ }
}