From dffc16e5b3478955fa4707a275040c833956d4e0 Mon Sep 17 00:00:00 2001 From: Zixuan Tan Date: Fri, 25 Aug 2023 19:00:07 +0800 Subject: [PATCH] runtime-rs: check peer close in log_forwarder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The log_forwarder task does not check if the peer has closed, causing a meaningless loop during the period of “kata vm exit”, when the peer closed, and “ShutdownContainer RPC received” that aborts the log forwarder. This patch fixes the problem. Fixes: #7741 Signed-off-by: Zixuan Tan --- .../crates/agent/src/log_forwarder.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/runtime-rs/crates/agent/src/log_forwarder.rs b/src/runtime-rs/crates/agent/src/log_forwarder.rs index 73c668f2be..221ddd6af1 100644 --- a/src/runtime-rs/crates/agent/src/log_forwarder.rs +++ b/src/runtime-rs/crates/agent/src/log_forwarder.rs @@ -64,16 +64,14 @@ impl LogForwarder { Ok(stream) => { let stream = BufReader::new(stream); let mut lines = stream.lines(); - while let Ok(line) = lines.next_line().await { - if let Some(l) = line { - match parse_agent_log_level(&l) { - LOG_LEVEL_TRACE => trace!(sl!(), "{}", l), - LOG_LEVEL_DEBUG => debug!(sl!(), "{}", l), - LOG_LEVEL_WARNING => warn!(sl!(), "{}", l), - LOG_LEVEL_ERROR => error!(sl!(), "{}", l), - LOG_LEVEL_CRITICAL => crit!(sl!(), "{}", l), - _ => info!(sl!(), "{}", l), - } + while let Ok(Some(l)) = lines.next_line().await { + match parse_agent_log_level(&l) { + LOG_LEVEL_TRACE => trace!(sl!(), "{}", l), + LOG_LEVEL_DEBUG => debug!(sl!(), "{}", l), + LOG_LEVEL_WARNING => warn!(sl!(), "{}", l), + LOG_LEVEL_ERROR => error!(sl!(), "{}", l), + LOG_LEVEL_CRITICAL => crit!(sl!(), "{}", l), + _ => info!(sl!(), "{}", l), } } }