From 63aff041889d4ef67aa7608b13cc7126b58bd11b Mon Sep 17 00:00:00 2001 From: Nyannyacha Date: Tue, 9 Jan 2024 16:13:53 +0900 Subject: [PATCH] fix: don't leave pending requests orphan state for a long time If the spawned user workers go to a retired state at once, then there will be no worker to accept the pending requests for a long time. So we must bring out their semaphore permits while going to a retired state so the pooler can create a fresh user worker. --- crates/base/src/rt_worker/worker_pool.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/base/src/rt_worker/worker_pool.rs b/crates/base/src/rt_worker/worker_pool.rs index a590f63d..81e5e044 100644 --- a/crates/base/src/rt_worker/worker_pool.rs +++ b/crates/base/src/rt_worker/worker_pool.rs @@ -534,12 +534,19 @@ impl WorkerPool { } fn retire(&mut self, key: &Uuid) { - if let Some(profile) = self.user_workers.get(key) { + if let Some(profile) = self.user_workers.get_mut(key) { let registry = self .active_workers .get_mut(&profile.service_path) .expect("registry must be initialized at this point"); + let _ = profile.permit.take(); + let (notify_tx, _) = registry.notify_pair.clone(); + + for _ in 0..notify_tx.receiver_count() { + let _ = notify_tx.send(None); + } + if registry.workers.contains(key) { registry.workers.remove(key); }