From 207e8066f3ed2f6c656e565c07c746e282f54ff4 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Tue, 3 Oct 2023 09:09:49 +0800 Subject: [PATCH] Dispose socket after connection failure (#2287) --- .../Balancer/Internal/SocketConnectivitySubchannelTransport.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Grpc.Net.Client/Balancer/Internal/SocketConnectivitySubchannelTransport.cs b/src/Grpc.Net.Client/Balancer/Internal/SocketConnectivitySubchannelTransport.cs index b602843f2..85669a691 100644 --- a/src/Grpc.Net.Client/Balancer/Internal/SocketConnectivitySubchannelTransport.cs +++ b/src/Grpc.Net.Client/Balancer/Internal/SocketConnectivitySubchannelTransport.cs @@ -190,6 +190,9 @@ public async ValueTask TryConnectAsync(ConnectContext context) } catch (Exception ex) { + // Socket is recreated every connect attempt. Explicitly dispose failed socket before next attempt. + socket.Dispose(); + SocketConnectivitySubchannelTransportLog.ErrorConnectingSocket(_logger, _subchannel.Id, currentEndPoint, ex); if (firstConnectionError == null)