File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed
test/Ydb.Sdk.Ado.Tests/Session Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -97,19 +97,26 @@ private async ValueTask<ISession> RentAsync(CancellationToken cancellationToken)
9797 // Statement order is important
9898 var waiterTcs = new TaskCompletionSource < T ? > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
9999 _waiters . Enqueue ( waiterTcs ) ;
100- if ( TryGetIdleSession ( out session ) )
100+ if ( _idleSessions . TryPop ( out session ) )
101101 {
102- if ( ! waiterTcs . TrySetResult ( null ) )
102+ if ( ! waiterTcs . TrySetResult ( null ) && waiterTcs . Task . IsCompleted )
103103 {
104- var raceSession = await waiterTcs . Task ;
104+ var sessionFromRace = waiterTcs . Task . Result ;
105105
106- if ( CheckIdleSession ( raceSession ) )
106+ if ( CheckIdleSession ( sessionFromRace ) )
107107 {
108- _idleSessions . Push ( raceSession ) ;
108+ _idleSessions . Push ( sessionFromRace ) ;
109109 }
110110 }
111111
112- return session ;
112+ if ( CheckIdleSession ( session ) )
113+ return session ;
114+
115+ session = await OpenNewSession ( finalToken ) . ConfigureAwait ( false ) ;
116+ if ( session != null )
117+ return session ;
118+
119+ continue ;
113120 }
114121
115122 await using var _ = finalToken . Register ( ( ) => waiterTcs . TrySetCanceled ( ) , useSynchronizationContext : false ) ;
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public async Task Reuse_Session_Before_Creating_new()
2828 [ Fact ]
2929 public async Task Creating_Session_Throw_Exception ( )
3030 {
31- for ( var it = 0 ; it < 100_000 ; it ++ )
31+ for ( var it = 0 ; it < 10_000 ; it ++ )
3232 {
3333 const string errorMessage = "Error on open session" ;
3434 const int maxSessionSize = 200 ;
You can’t perform that action at this time.
0 commit comments