1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(ext/websocket): order of ws writes (#19131)

Fixes https://github.com/denoland/deno/issues/19041
This commit is contained in:
Divy Srivastava 2023-05-18 20:16:19 +05:30 committed by Levente Kurusa
parent f19ee2221c
commit b733910528
No known key found for this signature in database
GPG key ID: 9F72F3C05BA137C4

View file

@ -283,6 +283,7 @@ where
let resource = ServerWebSocket {
ws: AsyncRefCell::new(FragmentCollector::new(stream)),
closed: Rc::new(Cell::new(false)),
tx_lock: AsyncRefCell::new(()),
};
let mut state = state.borrow_mut();
let rid = state.resource_table.add(resource);
@ -316,6 +317,7 @@ pub enum MessageKind {
pub struct ServerWebSocket {
ws: AsyncRefCell<FragmentCollector<WebSocketStream>>,
closed: Rc<Cell<bool>>,
tx_lock: AsyncRefCell<()>,
}
impl ServerWebSocket {
@ -324,6 +326,7 @@ impl ServerWebSocket {
self: Rc<Self>,
frame: Frame,
) -> Result<(), AnyError> {
let _lock = RcRef::map(&self, |r| &r.tx_lock).borrow_mut().await;
// SAFETY: fastwebsockets only needs a mutable reference to the WebSocket
// to populate the write buffer. We encounter an await point when writing
// to the socket after the frame has already been written to the buffer.
@ -360,6 +363,7 @@ pub fn ws_create_server_stream(
let ws_resource = ServerWebSocket {
ws: AsyncRefCell::new(FragmentCollector::new(ws)),
closed: Rc::new(Cell::new(false)),
tx_lock: AsyncRefCell::new(()),
};
let rid = state.resource_table.add(ws_resource);