From 3311459388be6e9d0d8793fb65971b4bb9a1d1e9 Mon Sep 17 00:00:00 2001 From: Denis Belous Date: Sun, 1 Oct 2023 11:02:39 +0300 Subject: [PATCH] Fixed an issue with a multi-threaded environment. --- MySQL.Data/src/MySqlPoolManager.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MySQL.Data/src/MySqlPoolManager.cs b/MySQL.Data/src/MySqlPoolManager.cs index d903f8813..76672befc 100644 --- a/MySQL.Data/src/MySqlPoolManager.cs +++ b/MySQL.Data/src/MySqlPoolManager.cs @@ -46,7 +46,7 @@ namespace MySql.Data.MySqlClient /// internal class MySqlPoolManager { - private static readonly Dictionary Pools = new Dictionary(); + private static readonly ConcurrentDictionary Pools = new ConcurrentDictionary(); private static readonly List ClearingPools = new List(); internal const int DEMOTED_TIMEOUT = 120000; @@ -146,7 +146,7 @@ public static async Task GetPoolAsync(MySqlConnectionStringBuilder se if (pool == null) { pool = await MySqlPool.CreateMySqlPoolAsync(settings, execAsync, cancellationToken).ConfigureAwait(false); - Pools.Add(text, pool); + Pools.TryAdd(text, pool); } else pool.Settings = settings; @@ -207,7 +207,7 @@ private static async Task ClearPoolByTextAsync(string key, bool execAsync) await pool.ClearAsync(execAsync).ConfigureAwait(false); // and then remove the pool from the active pools list - Pools.Remove(key); + Pools.TryRemove(key, out MySqlPool mySqlPool); semaphoreSlim.Release(); }