Skip to content

Commit

Permalink
Add retry to GetSession in SessionPool.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
XmasApple committed Sep 28, 2023
1 parent 78d5353 commit c389d3e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Ydb.Sdk/src/Services/Table/SessionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ public SessionPool(Driver driver, SessionPoolConfig config)
}

public async Task<GetSessionResponse> GetSession()
{
const int maxAttempts = 100;

GetSessionResponse getSessionResponse = null!;
for (var attempt = 0; attempt < maxAttempts; attempt++)
{
getSessionResponse = await GetSessionAttempt();
}

_logger.LogError($"Failed to get session from pool or create it (attempts: {maxAttempts})");
return getSessionResponse;
}

private async Task<GetSessionResponse> GetSessionAttempt()
{
lock (_lock)
{
Expand Down

0 comments on commit c389d3e

Please sign in to comment.