@@ -397,11 +397,14 @@ public static ConnectionPool GetPool(string connectionString)
397397 var newPool = new ConnectionPool ( connectionSettings ) ;
398398 pool = s_pools . GetOrAdd ( normalizedConnectionString , newPool ) ;
399399
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 )
402401 {
403- s_pools . GetOrAdd ( connectionString , pool ) ;
404402 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 ) ;
405408 }
406409 else if ( pool != newPool && Log . IsInfoEnabled ( ) )
407410 {
@@ -455,10 +458,13 @@ private ConnectionPool(ConnectionSettings cs)
455458 m_logArguments = new object [ ] { "{0}" . FormatInvariant ( Id ) } ;
456459 if ( Log . IsInfoEnabled ( ) )
457460 Log . Info ( "Pool{0} creating new connection pool for ConnectionString: {1}" , m_logArguments [ 0 ] , cs . ConnectionStringBuilder . GetConnectionString ( includePassword : false ) ) ;
461+ }
458462
459- if ( cs . ConnectionIdleTimeout > 0 )
463+ private void StartReaperTask ( )
464+ {
465+ if ( ConnectionSettings . ConnectionIdleTimeout > 0 )
460466 {
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 ) ) ) ;
462468 m_reaperTask = Task . Run ( async ( ) =>
463469 {
464470 while ( true )
@@ -527,7 +533,7 @@ public ConnectionStringPool(string connectionString, ConnectionPool pool)
527533 readonly ILoadBalancer m_loadBalancer ;
528534 readonly Dictionary < string , int > m_hostSessions ;
529535 readonly object [ ] m_logArguments ;
530- readonly Task m_reaperTask ;
536+ Task m_reaperTask ;
531537 uint m_lastRecoveryTime ;
532538 int m_lastSessionId ;
533539 Dictionary < string , CachedProcedure > m_procedureCache ;
0 commit comments