Bug #112582 Operations that change non-concurrent collections must have exclusive access
Submitted: 1 Oct 2023 8:04 Modified: 4 Oct 2023 11:57
Reporter: Denis Belous (OCA) Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:8.1.0 OS:Any
Assigned to: CPU Architecture:Any

[1 Oct 2023 8:04] Denis Belous
Description:
System.InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.    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)    at MySql.Data.MySqlClient.MySqlConnection.Open()

How to repeat:
Us a multi-threaded environment.

Suggested fix:
Use Concurrent Collections: In a multi-threaded environment, it's best to use concurrent collections that are designed to be thread-safe. In .NET, you have access to collections like ConcurrentDictionary and ConcurrentQueue which are designed for concurrent access.

Replace your regular Dictionary with a ConcurrentDictionary. This should help prevent concurrent update issues.

https://github.com/mysql/mysql-connector-net/pull/58
[2 Oct 2023 12:35] MySQL Verification Team
HI Mr. Belous,

Thank you for your bug report.

You have reported this as a bug in our Data Dictionary, which is a part of MySQL Server.

However, it seems that you report an advice on using Connector / NET.

We wait for your feedback.
[2 Oct 2023 15:25] Denis Belous
Yes, your are right. I wanted to add it to Connector/NET
[2 Oct 2023 23:46] Bradley Grainger
Duplicate of bug #110717.
[3 Oct 2023 8:39] Denis Belous
No problem, but they wrote that if you made a PR you need to create a bug post. I simple created because want to get quick fix in library.
[3 Oct 2023 10:09] MySQL Verification Team
Hi,

This bug is truly a duplicate of the  bug #110717.
[3 Oct 2023 10:28] Denis Belous
I know it, but I cannot create a pull request without posting a bug.
[3 Oct 2023 15:52] Bradley Grainger
You shouldn't create a pull request because the bug is already fixed (in the code, not yet shipped).
[4 Oct 2023 6:23] Denis Belous
I do not see any branch with fix. This is critical issue and we waiting for update for three months...
[4 Oct 2023 11:13] MySQL Verification Team
Hi,

This is a last comment from the original bug:

"
Fixed as of the upcoming MySQL Connector/NET 8.2.0 release.
"
[4 Oct 2023 11:57] Denis Belous
Approxmitly when we will get a new version of your library?
[4 Oct 2023 12:56] MySQL Verification Team
Hi,

Sorry, no idea ....

Keep watching C/NET download pages once per week.