From 5fc24cb86fdc1f8781d04a40cb92b49ea9bb7366 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 4546de9f6..999e17caa 100644 --- a/src/Ocelot/WebSockets/Middleware/WebSocketsProxyMiddleware.cs +++ b/src/Ocelot/WebSockets/Middleware/WebSocketsProxyMiddleware.cs @@ -46,6 +46,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) @@ -53,6 +57,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;