@@ -31,7 +31,7 @@ internal sealed class PoolingSessionSource : ISessionSource<IPoolingSession>
3131 private volatile bool _pruningTimerEnabled ;
3232 private int _pruningSampleIndex ;
3333
34- private volatile int _numConnectors ;
34+ private volatile int _numSessions ;
3535 private volatile int _idleCount ;
3636
3737 public PoolingSessionSource (
@@ -111,15 +111,15 @@ private async ValueTask<IPoolingSession> RentAsync(CancellationToken cancellatio
111111 return session ;
112112 }
113113
114- // If we're here, our waiting attempt on the idle connector channel was released with a null
115- // (or bad connector ), or we're in sync mode. Check again if a new idle connector has appeared since we last checked.
114+ // If we're here, our waiting attempt on the idle session channel was released with a null
115+ // (or bad session ), or we're in sync mode. Check again if a new idle session has appeared since we last checked.
116116 if ( TryGetIdleSession ( out session ) )
117117 {
118118 return session ;
119119 }
120120
121- // We might have closed a connector in the meantime and no longer be at max capacity
122- // so try to open a new connector and if that fails, loop again.
121+ // We might have closed a session in the meantime and no longer be at max capacity
122+ // so try to open a new session and if that fails, loop again.
123123 session = await OpenNewSession ( finalToken ) . ConfigureAwait ( false ) ;
124124 if ( session != null )
125125 {
@@ -139,9 +139,9 @@ private async ValueTask<IPoolingSession> RentAsync(CancellationToken cancellatio
139139
140140 private async ValueTask < IPoolingSession ? > OpenNewSession ( CancellationToken cancellationToken )
141141 {
142- for ( var numConnectors = _numConnectors ; numConnectors < _maxSessionSize ; numConnectors = _numConnectors )
142+ for ( var numSessions = _numSessions ; numSessions < _maxSessionSize ; numSessions = _numSessions )
143143 {
144- if ( Interlocked . CompareExchange ( ref _numConnectors , numConnectors + 1 , numConnectors ) != numConnectors )
144+ if ( Interlocked . CompareExchange ( ref _numSessions , numSessions + 1 , numSessions ) != numSessions )
145145 {
146146 continue ;
147147 }
@@ -153,8 +153,8 @@ private async ValueTask<IPoolingSession> RentAsync(CancellationToken cancellatio
153153
154154 // Only start pruning if we've incremented open count past _min.
155155 // Note that we don't do it only once, on equality, because the thread which incremented open count past _min might get exception
156- // on NpgsqlConnector .Open due to timeout, CancellationToken or other reasons.
157- if ( numConnectors >= _minSessionSize )
156+ // on NpgsqlSession .Open due to timeout, CancellationToken or other reasons.
157+ if ( numSessions >= _minSessionSize )
158158 {
159159 UpdatePruningTimer ( ) ;
160160 }
@@ -164,9 +164,9 @@ private async ValueTask<IPoolingSession> RentAsync(CancellationToken cancellatio
164164 catch
165165 {
166166 // Physical open failed, decrement the open and busy counter back down.
167- Interlocked . Decrement ( ref _numConnectors ) ;
167+ Interlocked . Decrement ( ref _numSessions ) ;
168168
169- // In case there's a waiting attempt on the channel, we write a null to the idle connector channel
169+ // In case there's a waiting attempt on the channel, we write a null to the idle session channel
170170 // to wake it up, so it will try opening (and probably throw immediately)
171171 // Statement order is important since we have synchronous completions on the channel.
172172 _idleSessionWriter . TryWrite ( null ) ;
@@ -220,15 +220,15 @@ private void CloseSession(IPoolingSession session)
220220 {
221221 session . DeleteSession ( ) ;
222222
223- var numConnectors = Interlocked . Decrement ( ref _numConnectors ) ;
223+ var numSessions = Interlocked . Decrement ( ref _numSessions ) ;
224224
225- // If a connector has been closed for any reason, we write a null to the idle connector channel to wake up
225+ // If a session has been closed for any reason, we write a null to the idle session channel to wake up
226226 // a waiter, who will open a new physical connection
227227 // Statement order is important since we have synchronous completions on the channel.
228228 _idleSessionWriter . TryWrite ( null ) ;
229229
230230 // Only turn off the timer one time, when it was this Close that brought Open back to _min.
231- if ( numConnectors == _minSessionSize )
231+ if ( numSessions == _minSessionSize )
232232 {
233233 UpdatePruningTimer ( ) ;
234234 }
@@ -238,13 +238,13 @@ private void UpdatePruningTimer()
238238 {
239239 lock ( _pruningTimer )
240240 {
241- var numConnectors = _numConnectors ;
242- if ( numConnectors > _minSessionSize && ! _pruningTimerEnabled )
241+ var numSessions = _numSessions ;
242+ if ( numSessions > _minSessionSize && ! _pruningTimerEnabled )
243243 {
244244 _pruningTimerEnabled = true ;
245245 _pruningTimer . Change ( _pruningSamplingInterval , Timeout . InfiniteTimeSpan ) ;
246246 }
247- else if ( numConnectors <= _minSessionSize && _pruningTimerEnabled )
247+ else if ( numSessions <= _minSessionSize && _pruningTimerEnabled )
248248 {
249249 _pruningTimer . Change ( Timeout . Infinite , Timeout . Infinite ) ;
250250 _pruningSampleIndex = 0 ;
@@ -285,7 +285,7 @@ private static void PruneIdleSessions(object? state)
285285 }
286286
287287 while ( toPrune > 0 &&
288- pool . _numConnectors > pool . _minSessionSize &&
288+ pool . _numSessions > pool . _minSessionSize &&
289289 pool . _idleSessionReader . TryRead ( out var session ) &&
290290 session != null )
291291 {
0 commit comments