From bc34cbbce559c6718d3e3237176d1bad927872a7 Mon Sep 17 00:00:00 2001 From: bin Date: Mon, 22 Feb 2021 21:44:36 +0800 Subject: [PATCH] agent: Stop receive message from Receiver if got None If the container has exited, the sender in notifier watching OOM events will be dropped after the loop exited, and recv() from the according receiver will get None. This will lead two problems for get_oom_event rpc all from agent: - return an wrong OOM event. - continuously return OOM events. Fixes: #1369 Signed-off-by: bin --- src/agent/rustjail/src/cgroups/notifier.rs | 5 ++++- src/agent/src/sandbox.rs | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/agent/rustjail/src/cgroups/notifier.rs b/src/agent/rustjail/src/cgroups/notifier.rs index c81da53b4a..1b4750a02a 100644 --- a/src/agent/rustjail/src/cgroups/notifier.rs +++ b/src/agent/rustjail/src/cgroups/notifier.rs @@ -191,7 +191,10 @@ async fn register_memory_event( let content = fs::read_to_string(path.clone()); info!( sl!(), - "OOM event for container: {}, content: {:?}", &containere_id, content + "cgroup event for container: {}, path: {:?}, content: {:?}", + &containere_id, + &path, + content ); } } diff --git a/src/agent/src/sandbox.rs b/src/agent/src/sandbox.rs index 946d1f4097..94b65f1d20 100644 --- a/src/agent/src/sandbox.rs +++ b/src/agent/src/sandbox.rs @@ -317,7 +317,13 @@ impl Sandbox { tokio::spawn(async move { loop { let event = rx.recv().await; + // None means the container has exited, + // and sender in OOM notifier is dropped. + if event.is_none() { + return; + } info!(logger, "got an OOM event {:?}", event); + let _ = tx .send(container_id.clone()) .await