From 1195087d4bcab9710242476aea43cc45a2a2c2e1 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Sun, 8 Oct 2023 18:01:48 +0700 Subject: [PATCH] Add more retryable IO errors --- src/common/instance.rs | 52 +++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/common/instance.rs b/src/common/instance.rs index fc6ac7c..9f0f080 100644 --- a/src/common/instance.rs +++ b/src/common/instance.rs @@ -131,19 +131,26 @@ impl NeoInstance { }, Ok(neolink_core::Error::Io(e)) => { log::debug!("Std IO Error"); - // Check if the inner error is the Other type and then the discomnect - let is_dropped = e.get_ref().is_some_and(|e| { - log::debug!("Std IO Error: Inner: {:?}", e); - matches!(e.downcast_ref::(), - Some(neolink_core::Error::DroppedConnection) | Some(neolink_core::Error::TimeoutDisconnected) - ) - }); - if is_dropped { - // Retry is a None + use std::io::ErrorKind::*; + if let ConnectionReset | ConnectionAborted | BrokenPipe | TimedOut = e.kind() { + // Resetable IO camera = None; None } else { - Some(Err(e.into())) + // Check if the inner error is the Other type and then the discomnect + let is_dropped = e.get_ref().is_some_and(|e| { + log::debug!("Std IO Error: Inner: {:?}", e); + matches!(e.downcast_ref::(), + Some(neolink_core::Error::DroppedConnection) | Some(neolink_core::Error::TimeoutDisconnected) + ) + }); + if is_dropped { + // Retry is a None + camera = None; + None + } else { + Some(Err(e.into())) + } } } Ok(e) => Some(Err(e.into())), @@ -154,18 +161,25 @@ impl NeoInstance { Ok(e) => { log::debug!("Std IO Error"); // Check if the inner error is the Other type and then the discomnect - let is_dropped = e.get_ref().is_some_and(|e| { - log::debug!("Std IO Error: Inner: {:?}", e); - matches!(e.downcast_ref::(), - Some(neolink_core::Error::DroppedConnection) | Some(neolink_core::Error::TimeoutDisconnected) - ) - }); - if is_dropped { - // Retry is a None + use std::io::ErrorKind::*; + if let ConnectionReset | ConnectionAborted | BrokenPipe | TimedOut = e.kind() { + // Resetable IO camera = None; None } else { - Some(Err(e.into())) + let is_dropped = e.get_ref().is_some_and(|e| { + log::debug!("Std IO Error: Inner: {:?}", e); + matches!(e.downcast_ref::(), + Some(neolink_core::Error::DroppedConnection) | Some(neolink_core::Error::TimeoutDisconnected) + ) + }); + if is_dropped { + // Retry is a None + camera = None; + None + } else { + Some(Err(e.into())) + } } }, Err(e) => {