From 25d2fb0fdecf5d76fcb8a4ecde5c54c0d4c3e240 Mon Sep 17 00:00:00 2001 From: Fupan Li Date: Tue, 26 Jul 2022 15:50:35 +0800 Subject: [PATCH] agent: fix the issue of exec hang with a backgroud process When run a exec process in backgroud without tty, the exec will hang and didn't terminated. For example: crictl -i sh -c 'nohup tail -f /dev/null &' Fixes: #4747 Signed-off-by: Fupan Li --- src/agent/rustjail/src/process.rs | 2 +- src/agent/src/rpc.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/agent/rustjail/src/process.rs b/src/agent/rustjail/src/process.rs index 0e7fe73efd..cdecae1308 100644 --- a/src/agent/rustjail/src/process.rs +++ b/src/agent/rustjail/src/process.rs @@ -161,7 +161,7 @@ impl Process { pub fn notify_term_close(&mut self) { let notify = self.term_exit_notifier.clone(); - notify.notify_one(); + notify.notify_waiters(); } pub fn close_stdin(&mut self) { diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index 447768b6bb..dede3204c8 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -603,15 +603,16 @@ impl AgentService { let cid = req.container_id; let eid = req.exec_id; - let mut term_exit_notifier = Arc::new(tokio::sync::Notify::new()); + let term_exit_notifier; let reader = { let s = self.sandbox.clone(); let mut sandbox = s.lock().await; let p = sandbox.find_container_process(cid.as_str(), eid.as_str())?; + term_exit_notifier = p.term_exit_notifier.clone(); + if p.term_master.is_some() { - term_exit_notifier = p.term_exit_notifier.clone(); p.get_reader(StreamType::TermMaster) } else if stdout { if p.parent_stdout.is_some() {