From 59677688ee968bd807ec3d8cbf6d8e27b19cb362 Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Tue, 6 Jan 2026 19:32:35 +0800 Subject: [PATCH] runtime-rs: Introduce a helper to check normal oom shutdown errors It mainly for checking if an error is a normal oom shutdown error due to network disconnection issues. Signed-off-by: Alex Lyn --- .../crates/runtimes/common/src/error.rs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/runtime-rs/crates/runtimes/common/src/error.rs b/src/runtime-rs/crates/runtimes/common/src/error.rs index 5e9fce6605..b2f7e1ce3b 100644 --- a/src/runtime-rs/crates/runtimes/common/src/error.rs +++ b/src/runtime-rs/crates/runtimes/common/src/error.rs @@ -21,3 +21,33 @@ pub enum Error { #[error("process already terminated")] ProcessAlreadyTerminated, } + +/// Common error messages indicating normal OOM shutdowns due to network issues. +const NORMAL_OOM_SHUTDOWN_MESSAGES: &[&str] = &[ + "Connection reset by peer", + "Broken pipe", + "transport endpoint is not connected", +]; + +/// Checks if an error indicates a normal oom shutdown due to network disconnections. +/// +/// This function identifies errors that commonly occur when a connection is gracefully +/// or unexpectedly terminated by the peer, such as network interruptions or the remote +/// end closing the connection. +pub fn is_normal_oom_shutdown_error(err: &anyhow::Error) -> bool { + // Check for common I/O error kinds that indicate connection issues. + if let Some(io_err) = err.downcast_ref::() { + match io_err.kind() { + std::io::ErrorKind::ConnectionReset + | std::io::ErrorKind::BrokenPipe + | std::io::ErrorKind::NotConnected => return true, + _ => {} + } + } + + // Additionally, check the error message for specific substrings. + let error_string = err.to_string().to_lowercase(); + NORMAL_OOM_SHUTDOWN_MESSAGES + .iter() + .any(|pattern| error_string.contains(&pattern.to_lowercase())) +}