Skip to content

Commit

Permalink
fix: dispose cache client when eager connection fails (#549)
Browse files Browse the repository at this point in the history
In order to clean up resources on a failed eager connection (`Ping`)
RPC, we dispose the cache client on exception in the
`CacheClient::CreateAsync`.
  • Loading branch information
malandis authored Mar 15, 2024
1 parent 8ee04fa commit aa9742e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Momento.Sdk/CacheClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ private ScsDataClient DataClient
public static async Task<ICacheClient> 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;
}

Expand Down

0 comments on commit aa9742e

Please sign in to comment.