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())) +}