diff --git a/services/tunnelbroker/src/websockets/session.rs b/services/tunnelbroker/src/websockets/session.rs index 47b9483e56..c6278cb19a 100644 --- a/services/tunnelbroker/src/websockets/session.rs +++ b/services/tunnelbroker/src/websockets/session.rs @@ -745,6 +745,10 @@ impl WebsocketSession { pub async fn send_message_to_device(&mut self, message: Message) { if let Err(e) = self.tx.send(message).await { + if should_ignore_error(&e) { + debug!("Ignored error when sending message to device: {e:?}"); + return; + } error!( errorType = error_types::WEBSOCKET_ERROR, "Failed to send message to device: {}", e @@ -866,3 +870,18 @@ impl WebsocketSession { Ok(()) } } + +fn should_ignore_error(err: &hyper_tungstenite::tungstenite::Error) -> bool { + use hyper_tungstenite::tungstenite::Error as E; + use std::io::ErrorKind; + + match err { + E::ConnectionClosed | E::AlreadyClosed => true, + E::Io(io_error) => match io_error.kind() { + // The operation failed because a pipe was closed. + ErrorKind::BrokenPipe => true, + _ => false, + }, + _ => false, + } +}