mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-22 00:00:11 +02:00
current-thread: fix shutdown on idle (#763)
When spawning using `Handle` while on the executor, tasks were being double counted. This prevented the number of active tasks to reach zero, thus preventing the executor from shutting down. This changes `spawn` to check if being called from the executor **before** incrementing the number of active tasks. Fixes #760
This commit is contained in:
@@ -653,6 +653,13 @@ impl Handle {
|
||||
where
|
||||
F: Future<Item = (), Error = ()> + Send + 'static,
|
||||
{
|
||||
if thread::current().id() == self.thread {
|
||||
let mut e = TaskExecutor::current();
|
||||
if e.id() == Some(self.id) {
|
||||
return e.spawn_local(Box::new(future));
|
||||
}
|
||||
}
|
||||
|
||||
if self.shut_down.get() {
|
||||
return Err(SpawnError::shutdown());
|
||||
}
|
||||
@@ -669,13 +676,6 @@ impl Handle {
|
||||
return Err(SpawnError::shutdown());
|
||||
}
|
||||
|
||||
if thread::current().id() == self.thread {
|
||||
let mut e = TaskExecutor::current();
|
||||
if e.id() == Some(self.id) {
|
||||
return e.spawn_local(Box::new(future));
|
||||
}
|
||||
}
|
||||
|
||||
self.sender.send(Box::new(future))
|
||||
.expect("CurrentThread does not exist anymore");
|
||||
// use 0 for the id, CurrentThread does not make use of it
|
||||
|
||||
Reference in New Issue
Block a user