mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 08:39:09 -05:00
fix(ext/websocket): prevent 'closed normally' panic (#12437)
This commit is contained in:
parent
f83c756aa0
commit
d6062b2653
3 changed files with 12 additions and 5 deletions
|
@ -417,6 +417,7 @@
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "closed":
|
||||||
case "close": {
|
case "close": {
|
||||||
this[_readyState] = CLOSED;
|
this[_readyState] = CLOSED;
|
||||||
|
|
||||||
|
|
|
@ -261,6 +261,7 @@
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "closed":
|
||||||
case "close": {
|
case "close": {
|
||||||
if (this[_closing]) {
|
if (this[_closing]) {
|
||||||
this[_closed].resolve(value);
|
this[_closed].resolve(value);
|
||||||
|
|
|
@ -82,7 +82,8 @@ pub struct WsStreamResource {
|
||||||
|
|
||||||
impl WsStreamResource {
|
impl WsStreamResource {
|
||||||
async fn send(self: &Rc<Self>, message: Message) -> Result<(), AnyError> {
|
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 { .. } => {
|
WebSocketStreamType::Client { .. } => {
|
||||||
let mut tx = RcRef::map(self, |r| match &r.stream {
|
let mut tx = RcRef::map(self, |r| match &r.stream {
|
||||||
WebSocketStreamType::Client { tx, .. } => tx,
|
WebSocketStreamType::Client { tx, .. } => tx,
|
||||||
|
@ -90,7 +91,7 @@ impl WsStreamResource {
|
||||||
})
|
})
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.await;
|
.await;
|
||||||
tx.send(message).await?;
|
tx.send(message).await
|
||||||
}
|
}
|
||||||
WebSocketStreamType::Server { .. } => {
|
WebSocketStreamType::Server { .. } => {
|
||||||
let mut tx = RcRef::map(self, |r| match &r.stream {
|
let mut tx = RcRef::map(self, |r| match &r.stream {
|
||||||
|
@ -99,11 +100,15 @@ impl WsStreamResource {
|
||||||
})
|
})
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.await;
|
.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(
|
async fn next_message(
|
||||||
|
|
Loading…
Reference in a new issue