Skip to content
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

[browser][ws] fix server initiated full close #97320

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading