Skip to content

Commit

Permalink
[browser] fix server initiated full close (#97320)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara authored Jan 22, 2024
1 parent 971ebdb commit 7e55140
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/libraries/System.Net.WebSockets.Client/tests/CloseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ public async Task CloseOutputAsync_ClientInitiated_CanReceive_CanClose(Uri serve
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
public async Task CloseOutputAsync_ServerInitiated_CanReceive(Uri server)
{
string message = "Hello WebSockets!";
var expectedCloseStatus = WebSocketCloseStatus.NormalClosure;
var expectedCloseDescription = ".shutdownafter";

Expand Down Expand Up @@ -303,9 +302,6 @@ await cws.SendAsync(

Assert.Equal(WebSocketState.CloseReceived, cws.State);

// Should be able to send.
await cws.SendAsync(WebSocketData.GetBufferFromText(message), WebSocketMessageType.Text, true, cts.Token);

// Cannot change the close status/description with the final close.
var closeStatus = PlatformDetection.IsNotBrowser ? WebSocketCloseStatus.InvalidPayloadData : (WebSocketCloseStatus)3210;
var closeDescription = "CloseOutputAsync_Client_Description";
Expand Down
5 changes: 5 additions & 0 deletions src/mono/browser/runtime/web-socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ export function ws_wasm_send(ws: WebSocketExtension, buffer_ptr: VoidPtr, buffer
if (ws[wasm_ws_is_aborted] || ws[wasm_ws_close_sent]) {
return rejectedPromise("InvalidState: The WebSocket is not connected.");
}
if (ws.readyState == WebSocket.CLOSED) {
// this is server initiated close but not partial close
// because CloseOutputAsync_ServerInitiated_CanSend expectations, we don't fail here
return resolvedPromise();
}

const buffer_view = new Uint8Array(localHeapViewU8().buffer, <any>buffer_ptr, buffer_length);
const whole_buffer = _mono_wasm_web_socket_send_buffering(ws, buffer_view, message_type, end_of_message);
Expand Down

0 comments on commit 7e55140

Please sign in to comment.