From aa9742ef81b44140b653d13b55ac7714c23c7294 Mon Sep 17 00:00:00 2001 From: Michael Landis Date: Fri, 15 Mar 2024 10:22:55 -0700 Subject: [PATCH] fix: dispose cache client when eager connection fails (#549) In order to clean up resources on a failed eager connection (`Ping`) RPC, we dispose the cache client on exception in the `CacheClient::CreateAsync`. --- src/Momento.Sdk/CacheClient.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Momento.Sdk/CacheClient.cs b/src/Momento.Sdk/CacheClient.cs index a47a9e03..ce448de5 100644 --- a/src/Momento.Sdk/CacheClient.cs +++ b/src/Momento.Sdk/CacheClient.cs @@ -51,7 +51,15 @@ private ScsDataClient DataClient public static async Task CreateAsync(IConfiguration config, ICredentialProvider authProvider, TimeSpan defaultTtl, TimeSpan eagerConnectionTimeout) { CacheClient cacheClient = new CacheClient(config, authProvider, defaultTtl); - await cacheClient.DataClient.EagerConnectAsync(eagerConnectionTimeout); + try + { + await cacheClient.DataClient.EagerConnectAsync(eagerConnectionTimeout); + } + catch (Exception e) + { + cacheClient.Dispose(); + throw e; + } return cacheClient; }