From 63a87090ffae9eb2ae21e2925a094dcf3abb5802 Mon Sep 17 00:00:00 2001 From: Hille Date: Mon, 9 May 2022 14:52:24 +0200 Subject: [PATCH] reopened pr #1030 --- .../WebSockets/Middleware/WebSocketsProxyMiddleware.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Ocelot/WebSockets/Middleware/WebSocketsProxyMiddleware.cs b/src/Ocelot/WebSockets/Middleware/WebSocketsProxyMiddleware.cs index db647f6dc..a247366e9 100644 --- a/src/Ocelot/WebSockets/Middleware/WebSocketsProxyMiddleware.cs +++ b/src/Ocelot/WebSockets/Middleware/WebSocketsProxyMiddleware.cs @@ -48,6 +48,10 @@ private static async Task PumpWebSocket(WebSocket source, WebSocket destination, catch (OperationCanceledException) { await destination.CloseOutputAsync(WebSocketCloseStatus.EndpointUnavailable, null, cancellationToken); + if (destination.State == WebSocketState.Open || destination.State == WebSocketState.CloseReceived) + { + await destination.CloseOutputAsync(WebSocketCloseStatus.EndpointUnavailable, null, cancellationToken); + } return; } catch (WebSocketException e) @@ -55,6 +59,10 @@ private static async Task PumpWebSocket(WebSocket source, WebSocket destination, if (e.WebSocketErrorCode == WebSocketError.ConnectionClosedPrematurely) { await destination.CloseOutputAsync(WebSocketCloseStatus.EndpointUnavailable, null, cancellationToken); + if (destination.State == WebSocketState.Open || destination.State == WebSocketState.CloseReceived) + { + await destination.CloseOutputAsync(WebSocketCloseStatus.EndpointUnavailable, null, cancellationToken); + } return; } throw;