diff --git a/src/agent/rustjail/src/cgroups/notifier.rs b/src/agent/rustjail/src/cgroups/notifier.rs index fb0a057b9e..e9819da4ae 100644 --- a/src/agent/rustjail/src/cgroups/notifier.rs +++ b/src/agent/rustjail/src/cgroups/notifier.rs @@ -77,9 +77,17 @@ async fn register_memory_event_v2( let mut inotify = Inotify::init().context("Failed to initialize inotify")?; // watching oom kill - let ev_wd = inotify.add_watch(&event_control_path, WatchMask::MODIFY)?; + let ev_wd = inotify + .add_watch(&event_control_path, WatchMask::MODIFY) + .context(format!("failed to add watch for {:?}", &event_control_path))?; + // Because no `unix.IN_DELETE|unix.IN_DELETE_SELF` event for cgroup file system, so watching all process exited - let cg_wd = inotify.add_watch(&cgroup_event_control_path, WatchMask::MODIFY)?; + let cg_wd = inotify + .add_watch(&cgroup_event_control_path, WatchMask::MODIFY) + .context(format!( + "failed to add watch for {:?}", + &cgroup_event_control_path + ))?; info!(sl(), "ev_wd: {:?}", ev_wd); info!(sl(), "cg_wd: {:?}", cg_wd); diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index 30f83aec7c..2ab66e3a62 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -342,24 +342,25 @@ impl AgentService { async fn do_start_container(&self, req: protocols::agent::StartContainerRequest) -> Result<()> { let mut s = self.sandbox.lock().await; let sid = s.id.clone(); - let cid = req.container_id; + let cid = req.container_id.clone(); let ctr = s .get_container(&cid) .ok_or_else(|| anyhow!("Invalid container id"))?; - ctr.exec().await?; - if sid == cid { - return Ok(()); + if sid != cid { + // start oom event loop + if let Ok(cg_path) = ctr.cgroup_manager.as_ref().get_cgroup_path("memory") { + let rx = notifier::notify_oom(cid.as_str(), cg_path.to_string()).await?; + s.run_oom_event_monitor(rx, cid.clone()).await; + } } - // start oom event loop - if let Ok(cg_path) = ctr.cgroup_manager.as_ref().get_cgroup_path("memory") { - let rx = notifier::notify_oom(cid.as_str(), cg_path.to_string()).await?; - s.run_oom_event_monitor(rx, cid).await; - } + let ctr = s + .get_container(&cid) + .ok_or_else(|| anyhow!("Invalid container id"))?; - Ok(()) + ctr.exec().await } #[instrument]