Skip to content

Commit

Permalink
fix: add error handling for general exception
Browse files Browse the repository at this point in the history
  • Loading branch information
lausannel authored Aug 26, 2024
1 parent acf44e2 commit 2f8a278
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/Apache.IoTDB/SessionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ public SessionPool(List<string> nodeUrls, string username, string password, int
public async Task<TResult> ExecuteClientOperationAsync<TResult>(AsyncOperation<TResult> operation, string errMsg, bool retryOnFailure = true)
{
Client client = _clients.Take();
Func<Client, Task<TResult>> executeWithReconnect = async (currentClient) =>
{
try
{
currentClient = await Reconnect(currentClient);
var response = await operation(currentClient);
return response;
}
catch (TException retryEx)
{
throw new TException(errMsg, retryEx);
}
};

try
{
var resp = await operation(client);
Expand All @@ -122,16 +136,18 @@ public async Task<TResult> ExecuteClientOperationAsync<TResult>(AsyncOperation<T
{
if (retryOnFailure)
{
try
{
client = await Reconnect(client);
var resp = await operation(client);
return resp;
}
catch (TException retryEx)
{
throw new TException(errMsg, retryEx);
}
return await executeWithReconnect(client);
}
else
{
throw new TException(errMsg, ex);
}
}
catch (Exception ex)
{
if (retryOnFailure)
{
return await executeWithReconnect(client);
}
else
{
Expand Down

0 comments on commit 2f8a278

Please sign in to comment.