blocking: fix spawn_blocking after shutdown (#1875)

The task handle needs to be shutdown explicitly and not dropped.

Closes #1853
This commit is contained in:
Carl Lerche
2019-12-01 12:58:01 -08:00
committed by GitHub
parent 8b60c5386a
commit a8a4a9f0fc
2 changed files with 21 additions and 1 deletions
+3
View File
@@ -197,6 +197,9 @@ impl Spawner {
let mut shared = self.inner.shared.lock().unwrap();
if shared.shutdown {
// Shutdown the task
task.shutdown();
// no need to even push this task; it would never get picked up
return;
}
+18 -1
View File
@@ -44,7 +44,7 @@ rt_test! {
use tokio::prelude::*;
use tokio::runtime::Runtime;
use tokio::sync::oneshot;
use tokio::time;
use tokio::{task, time};
use tokio_test::{assert_err, assert_ok};
use futures::future::poll_fn;
@@ -438,6 +438,23 @@ rt_test! {
});
}
#[test]
fn spawn_blocking_after_shutdown() {
let rt = rt();
let handle = rt.handle().clone();
// Shutdown
drop(rt);
handle.enter(|| {
let res = task::spawn_blocking(|| unreachable!());
// Avoid using a tokio runtime
let out = futures::executor::block_on(res);
assert!(out.is_err());
});
}
#[test]
fn io_driver_called_when_under_load() {
let mut rt = rt();