diff options
author | Leo K <crowlkats@toaxl.com> | 2021-10-19 18:21:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-19 18:21:15 +0200 |
commit | d6062b265331b88efcbe740741bd93714ec11026 (patch) | |
tree | e43eee055f38b8f1fb50381d7c5034a0ee115cd2 /ext/websocket/lib.rs | |
parent | f83c756aa0754d8507d6df1b4afc6fd516396c98 (diff) |
fix(ext/websocket): prevent 'closed normally' panic (#12437)
Diffstat (limited to 'ext/websocket/lib.rs')
-rw-r--r-- | ext/websocket/lib.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs index 32ac4cf03..d469b5aaf 100644 --- a/ext/websocket/lib.rs +++ b/ext/websocket/lib.rs @@ -82,7 +82,8 @@ pub struct WsStreamResource { impl WsStreamResource { async fn send(self: &Rc<Self>, message: Message) -> Result<(), AnyError> { - match self.stream { + use tokio_tungstenite::tungstenite::Error; + let res = match self.stream { WebSocketStreamType::Client { .. } => { let mut tx = RcRef::map(self, |r| match &r.stream { WebSocketStreamType::Client { tx, .. } => tx, @@ -90,7 +91,7 @@ impl WsStreamResource { }) .borrow_mut() .await; - tx.send(message).await?; + tx.send(message).await } WebSocketStreamType::Server { .. } => { let mut tx = RcRef::map(self, |r| match &r.stream { @@ -99,11 +100,15 @@ impl WsStreamResource { }) .borrow_mut() .await; - tx.send(message).await?; + tx.send(message).await } - } + }; - Ok(()) + match res { + Ok(()) => Ok(()), + Err(Error::ConnectionClosed) => Ok(()), + Err(err) => Err(err.into()), + } } async fn next_message( |