From e927bc3d2047be5baf43eca76a74c01b35c89d98 Mon Sep 17 00:00:00 2001 From: JKorf Date: Sun, 23 Jun 2024 14:55:20 +0200 Subject: [PATCH] Close socket when connecting and authentication fails --- CryptoExchange.Net/Clients/SocketApiClient.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CryptoExchange.Net/Clients/SocketApiClient.cs b/CryptoExchange.Net/Clients/SocketApiClient.cs index 0d981a42..064c5594 100644 --- a/CryptoExchange.Net/Clients/SocketApiClient.cs +++ b/CryptoExchange.Net/Clients/SocketApiClient.cs @@ -383,7 +383,11 @@ protected virtual async Task ConnectIfNeededAsync(SocketConnection s if (!authenticated || socket.Authenticated) return new CallResult(null); - return await AuthenticateSocketAsync(socket).ConfigureAwait(false); + var result = await AuthenticateSocketAsync(socket).ConfigureAwait(false); + if (!result) + await socket.CloseAsync().ConfigureAwait(false); + + return result; } ///