Skip to content

Commit 55ba0af

Browse files
fix
1 parent b3aab22 commit 55ba0af

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

src/Ydb.Sdk/src/Ado/Session/PoolingSessionSource.cs

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -87,45 +87,34 @@ private async ValueTask<IPoolingSession> RentAsync(CancellationToken cancellatio
8787

8888
var finalToken = ctsGetSession.Token;
8989

90-
try
90+
var session = await OpenNewSession(finalToken).ConfigureAwait(false);
91+
if (session != null)
92+
return session;
93+
94+
while (true)
9195
{
92-
var session = await OpenNewSession(finalToken).ConfigureAwait(false);
93-
if (session != null)
94-
return session;
96+
session = await _idleSessionReader.ReadAsync(finalToken).ConfigureAwait(false);
9597

96-
while (true)
98+
if (CheckIdleSession(session))
9799
{
98-
session = await _idleSessionReader.ReadAsync(finalToken).ConfigureAwait(false);
99-
100-
if (CheckIdleSession(session))
101-
{
102-
return session;
103-
}
100+
return session;
101+
}
104102

105-
// If we're here, our waiting attempt on the idle session channel was released with a null
106-
// (or bad session), or we're in sync mode. Check again if a new idle session has appeared since we last checked.
107-
if (TryGetIdleSession(out session))
108-
{
109-
return session;
110-
}
103+
// If we're here, our waiting attempt on the idle session channel was released with a null
104+
// (or bad session), or we're in sync mode. Check again if a new idle session has appeared since we last checked.
105+
if (TryGetIdleSession(out session))
106+
{
107+
return session;
108+
}
111109

112-
// We might have closed a session in the meantime and no longer be at max capacity
113-
// so try to open a new session and if that fails, loop again.
114-
session = await OpenNewSession(finalToken).ConfigureAwait(false);
115-
if (session != null)
116-
{
117-
return session;
118-
}
110+
// We might have closed a session in the meantime and no longer be at max capacity
111+
// so try to open a new session and if that fails, loop again.
112+
session = await OpenNewSession(finalToken).ConfigureAwait(false);
113+
if (session != null)
114+
{
115+
return session;
119116
}
120117
}
121-
catch (OperationCanceledException e)
122-
{
123-
throw new YdbException(StatusCode.Cancelled,
124-
$"The connection pool has been exhausted, either raise 'MaxSessionPool' " +
125-
$"(currently {_maxSessionSize}) or 'CreateSessionTimeout' " +
126-
$"(currently {_createSessionTimeout} seconds) in your connection string.", e
127-
);
128-
}
129118
}
130119

131120
private async ValueTask<IPoolingSession?> OpenNewSession(CancellationToken cancellationToken)

src/Ydb.Sdk/src/Ado/YdbConnection.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,18 @@ public override void ChangeDatabase(string databaseName)
9292
public override async Task OpenAsync(CancellationToken cancellationToken)
9393
{
9494
ThrowIfConnectionOpen();
95-
96-
Session = await PoolManager.GetSession(ConnectionStringBuilder, cancellationToken);
95+
try
96+
{
97+
Session = await PoolManager.GetSession(ConnectionStringBuilder, cancellationToken);
98+
}
99+
catch (OperationCanceledException e)
100+
{
101+
throw new YdbException(StatusCode.Cancelled,
102+
$"The connection pool has been exhausted, either raise 'MaxSessionPool' " +
103+
$"(currently {ConnectionStringBuilder.MaxSessionPool}) or 'CreateSessionTimeout' " +
104+
$"(currently {ConnectionStringBuilder.CreateSessionTimeout} seconds) in your connection string.", e
105+
);
106+
}
97107

98108
OnStateChange(ClosedToOpenEventArgs);
99109

0 commit comments

Comments
 (0)