From 791d55661e1cd0ebc097d7e9881093e34b8fa8c7 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Mon, 22 Jun 2026 14:59:05 +0800 Subject: [PATCH] fix(agent): prevent zombie processes on agent cleanup Root cause: - AgentDriverClient::kill() is called during Drop to clean up child processes - Old implementation called child.wait() and ignored errors with let _ - When wait() fails (e.g., process already killed by signal), child is not reaped and becomes zombie Fix: - Use try_wait() non-blocking polling, up to 100ms timeout - Avoid long blocking in Drop during async cleanup - Still perform final blocking wait() as fallback after timeout - Log all wait errors for debugging Impact: - All JDBC agents (Oracle/DB2/DM8/XuguDB etc.) - Prevents zombie process accumulation during long-running sessions --- crates/dbx-core/src/db/agent_driver.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/dbx-core/src/db/agent_driver.rs b/crates/dbx-core/src/db/agent_driver.rs index f669e5f478..1903ef927d 100644 --- a/crates/dbx-core/src/db/agent_driver.rs +++ b/crates/dbx-core/src/db/agent_driver.rs @@ -722,8 +722,24 @@ impl AgentDriverClient { if let Err(e) = self.child.kill() { log::warn!("Failed to kill agent process: {e}"); } - // Reap the child to avoid zombie processes - let _ = self.child.wait(); + // Reap the child to avoid zombie processes. + // Use try_wait() with a timeout instead of blocking wait() to avoid + // hanging in Drop during async cleanup. Poll up to 100ms for the + // process to exit after kill(). + for _ in 0..10 { + match self.child.try_wait() { + Ok(Some(_status)) => return, + Ok(None) => std::thread::sleep(Duration::from_millis(10)), + Err(e) => { + log::warn!("Failed to wait for agent process: {e}"); + return; + } + } + } + // Final blocking wait as a last resort + if let Err(e) = self.child.wait() { + log::warn!("Final wait failed for agent process: {e}"); + } } pub fn pid(&self) -> u32 {