From ab59a65c9265e51674ae56643c5e1c9d309c8241 Mon Sep 17 00:00:00 2001 From: Jianyong Wu Date: Wed, 1 Feb 2023 20:51:53 +0800 Subject: [PATCH] runtime-rs: neglect a certain error when delete cgroup Delete cgroup for a thread which may exit can lead to panic. Just neglect that error is harmless also avoid this failure. Fixes: #6192 Signed-off-by: Jianyong Wu --- .../crates/resource/src/cgroups/mod.rs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/runtime-rs/crates/resource/src/cgroups/mod.rs b/src/runtime-rs/crates/resource/src/cgroups/mod.rs index 8dbef7f64d..7787d2ad0d 100644 --- a/src/runtime-rs/crates/resource/src/cgroups/mod.rs +++ b/src/runtime-rs/crates/resource/src/cgroups/mod.rs @@ -9,6 +9,8 @@ mod utils; use std::{ collections::{HashMap, HashSet}, + error::Error, + io, iter::FromIterator, sync::Arc, }; @@ -24,6 +26,8 @@ use oci::LinuxResources; use persist::sandbox_persist::Persist; use tokio::sync::RwLock; +const OS_ERROR_NO_SUCH_PROCESS: i32 = 3; + pub struct CgroupArgs { pub sid: String, pub config: TomlConfig, @@ -109,7 +113,22 @@ impl CgroupsResource { /// overhead_cgroup_manager to the parent and then delete the cgroups. pub async fn delete(&self) -> Result<()> { for cg_pid in self.cgroup_manager.tasks() { - self.cgroup_manager.remove_task(cg_pid)?; + // For now, we can't guarantee that the thread in cgroup_manager does still + // exist. Once it exit, we should ignor that error returned by remove_task + // to let it go. + if let Err(error) = self.cgroup_manager.remove_task(cg_pid) { + match error.source() { + Some(err) => match err.downcast_ref::() { + Some(e) => { + if e.raw_os_error() != Some(OS_ERROR_NO_SUCH_PROCESS) { + return Err(error.into()); + } + } + None => return Err(error.into()), + }, + None => return Err(error.into()), + } + } } self.cgroup_manager