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
This commit is contained in:
1 parent
7adee1cacf
commit
791d55661e
1 file changed
+18
-2
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user