From 3e52a32b867ce79f1c9b8b49c782b878aca3a45b Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 13 May 2024 15:26:33 +0100 Subject: [PATCH] Fix cgroup.events error when cgroup is gone before reading events If cgroup is gone before reading the cgroup.events file then it will return an error. Treat errors as unpopulated to account for it. --- src/runc/container.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/runc/container.rs b/src/runc/container.rs index 0cd54ea..697a8b6 100644 --- a/src/runc/container.rs +++ b/src/runc/container.rs @@ -28,10 +28,15 @@ impl CgroupEventNotifier { fn populated(&mut self) -> Result { let file = self.file.get_mut(); - file.seek(std::io::SeekFrom::Start(0)) - .context("Cannot seek to start")?; + let Ok(_) = file.seek(std::io::SeekFrom::Start(0)) else { + return Ok(false); + }; for line in BufReader::new(file).lines() { - let line = line.context("Cannot read line")?; + let Ok(line) = line else { + // IO errors on cgroup.events file indicate that the cgroup has been deleted, so + // it is no longer populated. + return Ok(false); + }; if line.starts_with("populated ") { return Ok(line.ends_with('1')); }