From 29e78ee652a23da403385959dd618719e21a5c27 Mon Sep 17 00:00:00 2001 From: Paweł Dybiec Date: Sun, 27 Aug 2023 12:50:31 +0100 Subject: Terminate on connection error --- src/mattermost/client.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/mattermost/client.rs') diff --git a/src/mattermost/client.rs b/src/mattermost/client.rs index 83aa5f6..861e0a8 100644 --- a/src/mattermost/client.rs +++ b/src/mattermost/client.rs @@ -78,7 +78,7 @@ impl Client { pub(crate) async fn handle_websocket_stream( &mut self, handler: T, - mut shutdown: tokio::sync::mpsc::UnboundedReceiver<()>, + mut shutdown: tokio::sync::oneshot::Receiver<()>, ) -> Result<(), anyhow::Error> { let mut ws_stream = self.get_working_ws_stream().await?; loop { @@ -110,17 +110,15 @@ impl Client { debug!("Websocket message: {message:?}"); }, Some(Err(err)) =>{ - warn!("Error while reading message: {err} "); - if matches!(err,tungstenite::Error::Protocol(_)){ - ws_stream = self.get_working_ws_stream().await? - } + return Err(err.into()) } None => { + debug!("Stream closed, restarting"); ws_stream = self.get_working_ws_stream().await? }, } } - _ = shutdown.recv() => { + _ = &mut shutdown => { debug!("Shutting down gracefully"); return Ok(()) } -- cgit 1.4.1