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
This commit is contained in:
Émile Grégoire
2020-07-28 20:43:19 -07:00
committed by GitHub
parent 1562bb3144
commit 646fbae765
16 changed files with 139 additions and 24 deletions
+16 -1
View File
@@ -2,7 +2,7 @@
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
// Tests to run on both current-thread & therad-pool runtime variants.
// Tests to run on both current-thread & thread-pool runtime variants.
macro_rules! rt_test {
($($t:tt)*) => {
@@ -869,6 +869,21 @@ rt_test! {
}
#[test]
fn shutdown_wakeup_time() {
let mut runtime = rt();
runtime.block_on(async move {
tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
});
runtime.shutdown_timeout(Duration::from_secs(10_000));
}
// This test is currently ignored on Windows because of a
// rust-lang issue in thread local storage destructors.
// See https://github.com/rust-lang/rust/issues/74875
#[test]
#[cfg(not(windows))]
fn runtime_in_thread_local() {
use std::cell::RefCell;
use std::thread;