New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgraded WebSockets Don't Flush Frames @ v1.32.4 #18700
Comments
The issue you are experiencing is likely due to a change in the behavior of Deno's WebSocket implementation between versions 1.32.2 and 1.32.4. Specifically, in version 1.32.4, WebSocket frames sent from WebSocket.prototype.send on a WebSocket obtained from Deno.upgradeWebSocket do not get flushed until there is an incoming frame. This behavior is not present in version 1.32.2. To work around this issue, you can manually flush the WebSocket after sending a frame using the await client.flush() method. For example: javascript async function server() { app.use((context) => {
}); await app.listen("localhost:8080"); async function client() { let last: string | null = null; client.addEventListener("open", (event) => {
}); client.addEventListener("message", async (event) => {
}); await Promise.all([server(), client()]); |
…complete (#18705) Fixes #18700 Timeline of the events that lead to the bug. 1. WebSocket handshake complete 2. Server on `read_frame` holding an AsyncRefCell borrow of the WebSocket stream. 3. Client sends a TXT frame after a some time 4. Server recieves the frame and goes back to `read_frame`. 5. After some time, Server starts a `write_frame` but `read_frame` is still holding a borrow! ^--- Locked. read_frame needs to complete so we can resume the write. This commit changes all writes to directly borrow the `fastwebsocket::WebSocket` resource under the assumption that it won't affect ongoing reads.
…complete (#18705) Fixes #18700 Timeline of the events that lead to the bug. 1. WebSocket handshake complete 2. Server on `read_frame` holding an AsyncRefCell borrow of the WebSocket stream. 3. Client sends a TXT frame after a some time 4. Server recieves the frame and goes back to `read_frame`. 5. After some time, Server starts a `write_frame` but `read_frame` is still holding a borrow! ^--- Locked. read_frame needs to complete so we can resume the write. This commit changes all writes to directly borrow the `fastwebsocket::WebSocket` resource under the assumption that it won't affect ongoing reads.
WebSocket frames sent from
WebSocket.prototype.send
on aWebSocket
obtained fromDeno.upgradeWebSocket
do not get flushed until there is an incoming frame.Observe the following code.
Upon running this in Deno v1.32.4, the following output is recorded.
The output is not correct; the server sends "Consider your hand shaken." 2 seconds after the "Handshake"! frame, as a result of the client asking "Where's my handshake?", instead of 1 second afterwards. Modifying the code to remove the "Where's my handshake?" frame causes the program to not progress after the "Handshake!" frame.
The expected output can be seen in Deno v1.32.2.
In this version, the server correctly sends the "Consider your hand shaken." frame after 1 second, as programmed.
The text was updated successfully, but these errors were encountered: