From c389d3e68c2526320a676131c8781988aae72327 Mon Sep 17 00:00:00 2001 From: XmasApple Date: Thu, 28 Sep 2023 17:26:29 +0300 Subject: [PATCH] Add retry to GetSession in SessionPool.cs --- src/Ydb.Sdk/src/Services/Table/SessionPool.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Ydb.Sdk/src/Services/Table/SessionPool.cs b/src/Ydb.Sdk/src/Services/Table/SessionPool.cs index a014eb9a..4d297ab0 100644 --- a/src/Ydb.Sdk/src/Services/Table/SessionPool.cs +++ b/src/Ydb.Sdk/src/Services/Table/SessionPool.cs @@ -91,6 +91,20 @@ public SessionPool(Driver driver, SessionPoolConfig config) } public async Task 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 GetSessionAttempt() { lock (_lock) {