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 <jianyong.wu@arm.com>
This commit is contained in:
Jianyong Wu 2023-02-01 20:51:53 +08:00
parent 8ae14f6a55
commit ab59a65c92

View File

@ -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::<io::Error>() {
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