diff options
author | Émile Grégoire <eg@emilegregoire.ca> | 2020-07-28 23:43:19 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-28 20:43:19 -0700 |
commit | 646fbae76535e397ef79dbcaacb945d4c829f666 (patch) | |
tree | 49c00b3825463cae83eef0e1b65ee3d8266980c3 /tokio/src/runtime/spawner.rs | |
parent | 1562bb314482215eb7517e6b8b8bdecbacf10e79 (diff) |
rt: fix potential leak during runtime shutdown (#2649)
JoinHandle of threads created by the pool are now tracked and properly joined at
shutdown. If the thread does not return within the timeout, then it's not joined and
left to the OS for cleanup.
Also, break a cycle between wakers held by the timer and the runtime.
Fixes #2641, #2535
Diffstat (limited to 'tokio/src/runtime/spawner.rs')
-rw-r--r-- | tokio/src/runtime/spawner.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tokio/src/runtime/spawner.rs b/tokio/src/runtime/spawner.rs index d136945c..c5f2d17c 100644 --- a/tokio/src/runtime/spawner.rs +++ b/tokio/src/runtime/spawner.rs @@ -18,6 +18,17 @@ pub(crate) enum Spawner { ThreadPool(thread_pool::Spawner), } +impl Spawner { + pub(crate) fn shutdown(&mut self) { + #[cfg(feature = "rt-threaded")] + { + if let Spawner::ThreadPool(spawner) = self { + spawner.shutdown(); + } + } + } +} + cfg_rt_core! { impl Spawner { pub(crate) fn spawn<F>(&self, future: F) -> JoinHandle<F::Output> |