@@ -33,7 +33,7 @@ namespace MongoDB.Driver.Core.ConnectionPools
33
33
internal sealed partial class ExclusiveConnectionPool
34
34
{
35
35
// private methods
36
- private Exception CreateTimeoutException ( OperationContext operationContext , string message )
36
+ private Exception CreateTimeoutException ( TimeSpan elapsed , string message )
37
37
{
38
38
var checkOutsForCursorCount = _checkOutReasonCounter . GetCheckOutsCount ( CheckOutReason . Cursor ) ;
39
39
var checkOutsForTransactionCount = _checkOutReasonCounter . GetCheckOutsCount ( CheckOutReason . Transaction ) ;
@@ -47,7 +47,7 @@ private Exception CreateTimeoutException(OperationContext operationContext, stri
47
47
var checkOutsForOtherCount = checkOutsCount - checkOutsForCursorCount - checkOutsForTransactionCount ;
48
48
49
49
message =
50
- $ "Timed out after { operationContext . Elapsed . TotalMilliseconds } ms waiting for a connection from the connection pool. " +
50
+ $ "Timed out after { elapsed . TotalMilliseconds } ms waiting for a connection from the connection pool. " +
51
51
$ "maxPoolSize: { maxPoolSize } , " +
52
52
$ "connections in use by cursors: { checkOutsForCursorCount } , " +
53
53
$ "connections in use by transactions: { checkOutsForTransactionCount } , " +
@@ -296,9 +296,9 @@ private IConnectionHandle EndCheckingOut(PooledConnection pooledConnection, Oper
296
296
297
297
private void EnsureTimeout ( OperationContext operationContext )
298
298
{
299
- if ( operationContext . IsTimedOut ( ) )
299
+ if ( operationContext . IsTimedOut ( out var elapsed ) )
300
300
{
301
- throw _pool . CreateTimeoutException ( operationContext , $ "Timed out waiting for a connection after { operationContext . Elapsed . TotalMilliseconds } ms.") ;
301
+ throw _pool . CreateTimeoutException ( elapsed , $ "Timed out waiting for a connection after { elapsed . TotalMilliseconds } ms.") ;
302
302
}
303
303
}
304
304
@@ -308,7 +308,7 @@ private Exception CreateException(OperationContext operationContext) =>
308
308
SemaphoreSlimSignalable . SemaphoreWaitResult . Signaled =>
309
309
MongoConnectionPoolPausedException . ForConnectionPool ( _pool . _endPoint ) ,
310
310
SemaphoreSlimSignalable . SemaphoreWaitResult . TimedOut =>
311
- _pool . CreateTimeoutException ( operationContext , $ "Timed out waiting for a connection after { operationContext . Elapsed . TotalMilliseconds } ms.") ,
311
+ _pool . CreateTimeoutException ( operationContext . Elapsed , $ "Timed out waiting for a connection after { operationContext . Elapsed . TotalMilliseconds } ms.") ,
312
312
// should not be reached
313
313
_ => new InvalidOperationException ( $ "Invalid { _poolQueueWaitResult } .")
314
314
} ;
@@ -853,7 +853,7 @@ public PooledConnection CreateOpened(OperationContext operationContext)
853
853
854
854
if ( _connectingWaitStatus == SemaphoreSlimSignalable . SemaphoreWaitResult . TimedOut )
855
855
{
856
- _pool . CreateTimeoutException ( operationContext , $ "Timed out waiting for in connecting queue after { operationContext . Elapsed . TotalMilliseconds } ms.") ;
856
+ _pool . CreateTimeoutException ( operationContext . Elapsed , $ "Timed out waiting for in connecting queue after { operationContext . Elapsed . TotalMilliseconds } ms.") ;
857
857
}
858
858
859
859
return CreateOpenedInternal ( operationContext ) ;
@@ -885,13 +885,13 @@ public PooledConnection CreateOpenedOrReuse(OperationContext operationContext)
885
885
{
886
886
SemaphoreSlimSignalable . SemaphoreWaitResult . Signaled => _pool . _connectionHolder . Acquire ( ) ,
887
887
SemaphoreSlimSignalable . SemaphoreWaitResult . Entered => CreateOpenedInternal ( operationContext ) ,
888
- SemaphoreSlimSignalable . SemaphoreWaitResult . TimedOut => throw CreateTimeoutException ( operationContext ) ,
888
+ SemaphoreSlimSignalable . SemaphoreWaitResult . TimedOut => throw CreateTimeoutException ( operationContext . Elapsed ) ,
889
889
_ => throw new InvalidOperationException ( $ "Invalid wait result { _connectingWaitStatus } ")
890
890
} ;
891
891
892
- if ( connection == null && operationContext . IsTimedOut ( ) )
892
+ if ( connection == null && operationContext . IsTimedOut ( out var elapsed ) )
893
893
{
894
- throw CreateTimeoutException ( operationContext ) ;
894
+ throw CreateTimeoutException ( elapsed ) ;
895
895
}
896
896
}
897
897
@@ -924,13 +924,13 @@ public async Task<PooledConnection> CreateOpenedOrReuseAsync(OperationContext op
924
924
{
925
925
SemaphoreSlimSignalable . SemaphoreWaitResult . Signaled => _pool . _connectionHolder . Acquire ( ) ,
926
926
SemaphoreSlimSignalable . SemaphoreWaitResult . Entered => await CreateOpenedInternalAsync ( operationContext ) . ConfigureAwait ( false ) ,
927
- SemaphoreSlimSignalable . SemaphoreWaitResult . TimedOut => throw CreateTimeoutException ( operationContext ) ,
927
+ SemaphoreSlimSignalable . SemaphoreWaitResult . TimedOut => throw CreateTimeoutException ( operationContext . Elapsed ) ,
928
928
_ => throw new InvalidOperationException ( $ "Invalid wait result { _connectingWaitStatus } ")
929
929
} ;
930
930
931
- if ( connection == null && operationContext . IsTimedOut ( ) )
931
+ if ( connection == null && operationContext . IsTimedOut ( out var elapsed ) )
932
932
{
933
- throw CreateTimeoutException ( operationContext ) ;
933
+ throw CreateTimeoutException ( elapsed ) ;
934
934
}
935
935
}
936
936
@@ -987,7 +987,7 @@ private void StartCreating(OperationContext operationContext)
987
987
_pool . _eventLogger . LogAndPublish ( new ConnectionPoolAddingConnectionEvent ( _pool . _serverId , EventContext . OperationId ) ) ;
988
988
989
989
operationContext . CancellationToken . ThrowIfCancellationRequested ( ) ;
990
- if ( operationContext . IsTimedOut ( ) )
990
+ if ( operationContext . IsTimedOut ( out _ ) )
991
991
{
992
992
throw new TimeoutException ( ) ;
993
993
}
@@ -1004,10 +1004,10 @@ private void FinishCreating(ConnectionDescription description, OperationContext
1004
1004
_pool . _serviceStates . IncrementConnectionCount ( description ? . ServiceId ) ;
1005
1005
}
1006
1006
1007
- private Exception CreateTimeoutException ( OperationContext operationContext )
1007
+ private Exception CreateTimeoutException ( TimeSpan elapsed )
1008
1008
{
1009
- var message = $ "Timed out waiting in connecting queue after { operationContext . Elapsed . TotalMilliseconds } ms.";
1010
- return _pool . CreateTimeoutException ( operationContext , message ) ;
1009
+ var message = $ "Timed out waiting in connecting queue after { elapsed . TotalMilliseconds } ms.";
1010
+ return _pool . CreateTimeoutException ( elapsed , message ) ;
1011
1011
}
1012
1012
}
1013
1013
}
0 commit comments