Skip to content

Commit

Permalink
Fixed concurrency issue on creating new pool when executed in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mhofman committed Oct 4, 2023
1 parent a3d6257 commit 1de887f
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions Snowflake.Data/Core/Session/ConnectionPoolManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1de887f

Please sign in to comment.