diff options
author | Paweł Dybiec <pawel@dybiec.info> | 2023-08-27 12:50:31 +0100 |
---|---|---|
committer | Paweł Dybiec <pawel@dybiec.info> | 2023-08-27 12:50:31 +0100 |
commit | 29e78ee652a23da403385959dd618719e21a5c27 (patch) | |
tree | c0d35a9c7235bd54a114f38c486f749187f250a8 /src/mattermost | |
parent | Use nix for docker builds (diff) |
Terminate on connection error
Diffstat (limited to 'src/mattermost')
-rw-r--r-- | src/mattermost/client.rs | 10 |
1 files changed, 4 insertions, 6 deletions
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<T: Handler>( &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(()) } |