@@ -397,11 +397,14 @@ public static ConnectionPool GetPool(string connectionString)
397
397
var newPool = new ConnectionPool ( connectionSettings ) ;
398
398
pool = s_pools . GetOrAdd ( normalizedConnectionString , newPool ) ;
399
399
400
- // if we won the race to create the new pool, also store it under the original connection string
401
- if ( pool == newPool && connectionString != normalizedConnectionString )
400
+ if ( pool == newPool )
402
401
{
403
- s_pools . GetOrAdd ( connectionString , pool ) ;
404
402
s_mruCache = new ConnectionStringPool ( connectionString , pool ) ;
403
+ pool . StartReaperTask ( ) ;
404
+
405
+ // if we won the race to create the new pool, also store it under the original connection string
406
+ if ( connectionString != normalizedConnectionString )
407
+ s_pools . GetOrAdd ( connectionString , pool ) ;
405
408
}
406
409
else if ( pool != newPool && Log . IsInfoEnabled ( ) )
407
410
{
@@ -455,10 +458,13 @@ private ConnectionPool(ConnectionSettings cs)
455
458
m_logArguments = new object [ ] { "{0}" . FormatInvariant ( Id ) } ;
456
459
if ( Log . IsInfoEnabled ( ) )
457
460
Log . Info ( "Pool{0} creating new connection pool for ConnectionString: {1}" , m_logArguments [ 0 ] , cs . ConnectionStringBuilder . GetConnectionString ( includePassword : false ) ) ;
461
+ }
458
462
459
- if ( cs . ConnectionIdleTimeout > 0 )
463
+ private void StartReaperTask ( )
464
+ {
465
+ if ( ConnectionSettings . ConnectionIdleTimeout > 0 )
460
466
{
461
- var reaperInterval = TimeSpan . FromSeconds ( Math . Max ( 1 , Math . Min ( 60 , cs . ConnectionIdleTimeout / 2 ) ) ) ;
467
+ var reaperInterval = TimeSpan . FromSeconds ( Math . Max ( 1 , Math . Min ( 60 , ConnectionSettings . ConnectionIdleTimeout / 2 ) ) ) ;
462
468
m_reaperTask = Task . Run ( async ( ) =>
463
469
{
464
470
while ( true )
@@ -527,7 +533,7 @@ public ConnectionStringPool(string connectionString, ConnectionPool pool)
527
533
readonly ILoadBalancer m_loadBalancer ;
528
534
readonly Dictionary < string , int > m_hostSessions ;
529
535
readonly object [ ] m_logArguments ;
530
- readonly Task m_reaperTask ;
536
+ Task m_reaperTask ;
531
537
uint m_lastRecoveryTime ;
532
538
int m_lastSessionId ;
533
539
Dictionary < string , CachedProcedure > m_procedureCache ;
0 commit comments