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

task: fix panic when dropping LocalSet #1843

Merged
merged 2 commits into from Nov 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 31 additions & 2 deletions tokio/src/task/local.rs
Expand Up @@ -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>) {
Expand Down Expand Up @@ -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);
}
}