Skip to content

Commit 5f3484c

Browse files
Call CloseAsync instead of CloseOutputAsync in the browser (#46012)
1 parent 6f1752a commit 5f3484c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/WebSocketsTransport.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,17 @@ private async Task StartSending(WebSocket socket)
491491
{
492492
try
493493
{
494-
// We're done sending, send the close frame to the client if the websocket is still open
495-
await socket.CloseOutputAsync(error != null ? WebSocketCloseStatus.InternalServerError : WebSocketCloseStatus.NormalClosure, "", _stopCts.Token).ConfigureAwait(false);
494+
if (!OperatingSystem.IsBrowser())
495+
{
496+
// We're done sending, send the close frame to the client if the websocket is still open
497+
await socket.CloseOutputAsync(error != null ? WebSocketCloseStatus.InternalServerError : WebSocketCloseStatus.NormalClosure, "", _stopCts.Token).ConfigureAwait(false);
498+
}
499+
else
500+
{
501+
// WebSocket in the browser doesn't have an equivalent to CloseOutputAsync, it just calls CloseAsync and logs a warning
502+
// So let's just call CloseAsync to avoid the warning
503+
await socket.CloseAsync(error != null ? WebSocketCloseStatus.InternalServerError : WebSocketCloseStatus.NormalClosure, "", _stopCts.Token).ConfigureAwait(false);
504+
}
496505
}
497506
catch (Exception ex)
498507
{

0 commit comments

Comments
 (0)