diff --git a/Snowflake.Data/Core/Session/ConnectionPoolManagerBase.cs b/Snowflake.Data/Core/Session/ConnectionPoolManagerBase.cs index 0ebca2022..3f6dffd85 100644 --- a/Snowflake.Data/Core/Session/ConnectionPoolManagerBase.cs +++ b/Snowflake.Data/Core/Session/ConnectionPoolManagerBase.cs @@ -31,23 +31,25 @@ protected ConnectionPoolManagerBase() protected virtual string GetPoolKey(string connectionString) => connectionString; - public void ClearAllPools() - { - Pools.Values.ToList().ForEach(pool => pool.ClearAllPools()); - } - public virtual SessionPool GetPool(string connectionString, SecureString password) { string poolKey = GetPoolKey(connectionString); - if (Pools.TryGetValue(poolKey, out var pool)) + if (Pools.ContainsKey(poolKey)) + return Pools[poolKey]; + lock (PoolsLock) + { + var pool = CreateSessionPool(connectionString, password); + ApplyPoolDefaults(pool); + Pools.Add(poolKey, pool); return pool; - - pool = CreateSessionPool(connectionString, password); - ApplyPoolDefaults(pool); - Pools.Add(poolKey, pool); - return pool; + } } - + + public void ClearAllPools() + { + Pools.Values.ToList().ForEach(pool => pool.ClearAllPools()); + } + public virtual void SetMaxPoolSize(int size) => throw FeatureNotAvailableForPoolVersion(); public virtual int GetMaxPoolSize() => throw FeatureNotAvailableForPoolVersion(); public virtual void SetTimeout(long time) => throw FeatureNotAvailableForPoolVersion();