From 35c700140fd94c44d05c652a450da35340c002a2 Mon Sep 17 00:00:00 2001 From: Brennan Date: Tue, 10 Jan 2023 15:35:10 -0800 Subject: [PATCH] Call CloseAsync instead of CloseOutputAsync in the browser --- .../src/Internal/WebSocketsTransport.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/WebSocketsTransport.cs b/src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/WebSocketsTransport.cs index d3932d83456e..b6d8190c04cb 100644 --- a/src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/WebSocketsTransport.cs +++ b/src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/WebSocketsTransport.cs @@ -463,8 +463,17 @@ private async Task StartSending(WebSocket socket) { try { - // We're done sending, send the close frame to the client if the websocket is still open - await socket.CloseOutputAsync(error != null ? WebSocketCloseStatus.InternalServerError : WebSocketCloseStatus.NormalClosure, "", _stopCts.Token).ConfigureAwait(false); + if (!OperatingSystem.IsBrowser()) + { + // We're done sending, send the close frame to the client if the websocket is still open + await socket.CloseOutputAsync(error != null ? WebSocketCloseStatus.InternalServerError : WebSocketCloseStatus.NormalClosure, "", _stopCts.Token).ConfigureAwait(false); + } + else + { + // WebSocket in the browser doesn't have an equivalent to CloseOutputAsync, it just calls CloseAsync and logs a warning + // So let's just call CloseAsync to avoid the warning + await socket.CloseAsync(error != null ? WebSocketCloseStatus.InternalServerError : WebSocketCloseStatus.NormalClosure, "", _stopCts.Token).ConfigureAwait(false); + } } catch (Exception ex) {