@@ -42,40 +42,29 @@ internal async Task<TSession> GetSession(CancellationToken cancellationToken = d
4242 throw new YdbException ( "Session pool is closed" ) ;
4343 }
4444
45- try
46- {
47- await _semaphore . WaitAsync ( finalCancellationToken ) ;
48- Interlocked . Decrement ( ref _waitingCount ) ;
49-
50- if ( _idleSessions . TryDequeue ( out var session ) && session . IsActive )
51- {
52- return session ;
53- }
45+ await _semaphore . WaitAsync ( finalCancellationToken ) ;
46+ Interlocked . Decrement ( ref _waitingCount ) ;
5447
55- if ( session != null ) // not active
56- {
57- Logger . LogDebug ( "Session[{Id}] isn't active, creating new session" , session . SessionId ) ;
58- }
48+ if ( _idleSessions . TryDequeue ( out var session ) && session . IsActive )
49+ {
50+ return session ;
51+ }
5952
60- try
61- {
62- return await CreateSession ( finalCancellationToken ) ;
63- }
64- catch ( Exception e )
65- {
66- Release ( ) ;
53+ if ( session != null ) // not active
54+ {
55+ Logger . LogDebug ( "Session[{Id}] isn't active, creating new session" , session . SessionId ) ;
56+ }
6757
68- Logger . LogError ( e , "Failed to create a session" ) ;
69- throw ;
70- }
58+ try
59+ {
60+ return await CreateSession ( finalCancellationToken ) ;
7161 }
72- catch ( Exception e ) when (
73- e is Driver . TransportException { Status . StatusCode : StatusCode . Cancelled } or OperationCanceledException
74- )
62+ catch ( Exception e )
7563 {
76- throw new YdbException ( $ "The connection pool has been exhausted, either raise 'MaxSessionPool' " +
77- $ "(currently { _size } ) or 'CreateSessionTimeout' " +
78- $ "(currently { _createSessionTimeoutMs / 1000 } seconds) in your connection string.") ;
64+ Release ( ) ;
65+
66+ Logger . LogError ( e , "Failed to create a session" ) ;
67+ throw ;
7968 }
8069 }
8170
0 commit comments