Skip to content

Commit e2b44df

Browse files
committed
add exec delete timeout
Signed-off-by: kuangmingfu <kuang.mingfu@zte.com.cn>
1 parent 6a5c9c2 commit e2b44df

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

crates/runc-shim/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
*/
1616

1717
use std::env;
18-
use tokio::runtime::Builder;
18+
1919
use containerd_shim::{asynchronous::run, parse};
20+
use tokio::runtime::Builder;
2021

2122
mod cgroup_memory;
2223
mod common;

crates/runc-shim/src/runc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,9 @@ impl ProcessLifecycle<ExecProcess> for RuncExecLifecycle {
457457

458458
async fn delete(&self, p: &mut ExecProcess) -> Result<()> {
459459
self.exit_signal.signal();
460+
self.exit_signal
461+
.wait_for_exit(tokio::time::Duration::from_secs(2))
462+
.await;
460463
let exec_pid_path = Path::new(self.bundle.as_str()).join(format!("{}.pid", p.id));
461464
remove_file(exec_pid_path).await.unwrap_or_default();
462465
Ok(())

crates/shim/src/asynchronous/mod.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use nix::{
4747
unistd::Pid,
4848
};
4949
use signal_hook_tokio::Signals;
50-
use tokio::{io::AsyncWriteExt, sync::Notify};
50+
use tokio::{self, io::AsyncWriteExt, sync::Notify, time::Duration};
5151

5252
use crate::{
5353
args,
@@ -237,6 +237,22 @@ impl ExitSignal {
237237
notified.await;
238238
}
239239
}
240+
241+
/// Wait for the exit signal to be set or return after a timeout.
242+
pub async fn wait_for_exit(&self, timeout_duration: Duration) {
243+
let timeout_task = async {
244+
tokio::time::sleep(timeout_duration).await;
245+
};
246+
247+
let exit_task = async {
248+
self.wait().await;
249+
};
250+
251+
tokio::select! {
252+
_ = timeout_task => {},
253+
_ = exit_task => {},
254+
}
255+
}
240256
}
241257

242258
/// Spawn is a helper func to launch shim process asynchronously.

0 commit comments

Comments
 (0)