From d69d1f1c294518bc578b4a663d4aafaa7e25863e Mon Sep 17 00:00:00 2001 From: Jonathan Bastien-Filiatrault Date: Tue, 17 Sep 2019 07:28:00 -0400 Subject: [PATCH 1/2] Decrement thread count on thread exit. I hit a problem that after 10 seconds idle, no blocking tasks would run anymore as all blocking threads exited and the Pool was convinced that there were still runners available. --- tokio-executor/src/blocking.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tokio-executor/src/blocking.rs b/tokio-executor/src/blocking.rs index b24be56fa6b..aae5ea4782b 100644 --- a/tokio-executor/src/blocking.rs +++ b/tokio-executor/src/blocking.rs @@ -118,6 +118,8 @@ fn spawn_thread() { run_task(task); continue 'outer; } else if timeout_result.timed_out() { + shared.num_idle -= 1; + shared.num_th -= 1; break 'outer; } } From ba5c7f07a420b5672f9ba4b17c113425fbd36c01 Mon Sep 17 00:00:00 2001 From: Jonathan Bastien-Filiatrault Date: Tue, 17 Sep 2019 08:51:54 -0400 Subject: [PATCH 2/2] Substract from num_idle AT MOST once. A notify at the wrong time can otherwise get us to underflow. --- tokio-executor/src/blocking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tokio-executor/src/blocking.rs b/tokio-executor/src/blocking.rs index aae5ea4782b..424d4676743 100644 --- a/tokio-executor/src/blocking.rs +++ b/tokio-executor/src/blocking.rs @@ -118,7 +118,7 @@ fn spawn_thread() { run_task(task); continue 'outer; } else if timeout_result.timed_out() { - shared.num_idle -= 1; + shared.num_idle = shared.num_idle.saturating_sub(1); shared.num_th -= 1; break 'outer; }