@@ -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 )
0 commit comments