Skip to content

Commit cea5523

Browse files
jokemanfiremxpv
authored andcommitted
fix(update): avoid update resource while the process is zombie
add a check in zombie init process Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
1 parent 9b5727a commit cea5523

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

crates/runc-shim/src/runc.rs

+31
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ use crate::{
6565
io::Stdio,
6666
};
6767

68+
/// check the process is zombie
69+
#[cfg(target_os = "linux")]
70+
fn is_zombie_process(pid: i32) -> bool {
71+
if let Ok(status) = std::fs::read_to_string(format!("/proc/{}/status", pid)) {
72+
for line in status.lines() {
73+
if line.starts_with("State:") && line.contains('Z') {
74+
return true;
75+
}
76+
}
77+
}
78+
false
79+
}
80+
6881
pub type ExecProcess = ProcessTemplate<RuncExecLifecycle>;
6982
pub type InitProcess = ProcessTemplate<RuncInitLifecycle>;
7083

@@ -311,6 +324,15 @@ impl ProcessLifecycle<InitProcess> for RuncInitLifecycle {
311324
p.pid
312325
));
313326
}
327+
328+
// check the process is zombie
329+
if is_zombie_process(p.pid) {
330+
return Err(other!(
331+
"failed to update resources because process {} is a zombie",
332+
p.pid
333+
));
334+
}
335+
314336
containerd_shim::cgroup::update_resources(p.pid as u32, resources)
315337
}
316338

@@ -327,6 +349,15 @@ impl ProcessLifecycle<InitProcess> for RuncInitLifecycle {
327349
p.pid
328350
));
329351
}
352+
353+
// check the process is zombie
354+
if is_zombie_process(p.pid) {
355+
return Err(other!(
356+
"failed to collect metrics because process {} is a zombie",
357+
p.pid
358+
));
359+
}
360+
330361
containerd_shim::cgroup::collect_metrics(p.pid as u32)
331362
}
332363

0 commit comments

Comments
 (0)