From f863f3139521a4261668a7e884d8534d14f2f140 Mon Sep 17 00:00:00 2001 From: "quanwei.zqw" Date: Fri, 23 Sep 2022 10:16:40 +0800 Subject: [PATCH] fix: support retry for rmdir cgroup path Compatible with runC for remove dir operation https://github.com/opencontainers/runc/blob/main/libcontainer/cgroups/utils.go#L272 Signed-off-by: quanwei.zqw --- src/lib.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 92062fa..8ac8aec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -332,7 +332,23 @@ where return Ok(()); } - remove_dir(self.get_path()) + // Compatible with runC for remove dir operation + // https://github.com/opencontainers/runc/blob/main/libcontainer/cgroups/utils.go#L272 + // + // We trying to remove all paths five times with increasing delay between tries. + // If after all there are not removed cgroups - appropriate error will be + // returned. + let mut delay = std::time::Duration::from_millis(10); + let cgroup_path = self.get_path(); + for _i in 0..4 { + if let Ok(()) = remove_dir(cgroup_path) { + return Ok(()); + } + std::thread::sleep(delay); + delay *= 2; + } + + remove_dir(cgroup_path) } /// Attach a task to this controller.