Description:
See https://github.com/mysql/mysql-connector-net/commit/291c2f31fa9d7bf1b3c02bd7da19db1b66f89a...
In this commit (in 8.0.33), the lock in the GetPool method is modified to SemaphoreSlim.
But this semaphore instance does not work as expected. Because every time this method is called, a new SemaphoreSlim instance is created.
That is, there are no locks here. When concurrent, Pools.Add may throw an exception.
System.ArgumentException: An item with the same key has already been added. Key: {my connection string}
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at MySql.Data.MySqlClient.MySqlPoolManager.GetPoolAsync(MySqlConnectionStringBuilder settings, Boolean execAsync, CancellationToken cancellationToken)
at MySql.Data.MySqlClient.MySqlConnection.OpenAsync(Boolean execAsync, CancellationToken cancellationToken)
How to repeat:
1. 8.0.33+
2. Use pools
3. Open MySqlConnections in multiple threads.
Suggested fix:
a. Still using lock(Pools) { ... }
b. Define semaphoreSlim in the class (static property), not in the method.