Bug #100327 Error when connecting db in parallel (multiple hosts in connection string)
Description:
When multiple hosts are specified in connection string and connected to DB in parallel, the following errors occur intermittently.
-------------------------------------------------------------------------
Results from .NET Core 3.1.
Error NO 1.
Object reference not set to an instance of an object.
at MySql.Data.Failover.FailoverManager.AttemptConnection(MySqlConnection connection, String originalConnectionString, String& connectionString, Boolean mySqlPoolManager)
at MySql.Data.MySqlClient.MySqlConnection.Open()
at System.Data.Common.DbConnection.OpenAsync(CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at ConsoleApp1.Program.<>c__DisplayClass0_0.<<Main>b__0>d.MoveNext() in Program.cs:line 38
Error No 2.
Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.Dictionary`2.KeyCollection.Enumerator.MoveNext()
at System.Data.Common.DbConnectionStringBuilder.get_ConnectionString()
at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
at MySql.Data.MySqlClient.MySqlConnection.Open()
at System.Data.Common.DbConnection.OpenAsync(CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at ConsoleApp1.Program.<>c__DisplayClass0_0.<<Main>b__0>d.MoveNext() in Program.cs:line 38
Error No 3.
Authentication to host 'xxx.xxx.xxx.xxx' for user 'xxxxx' using method 'mysql_native_password' failed with message: Access denied for user ''@'xxx.xxx.xxx.xxx' (using password: NO)
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex)
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset)
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at System.Data.Common.DbConnection.OpenAsync(CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at ConsoleApp1.Program.<>c__DisplayClass0_0.<<Main>b__0>d.MoveNext() in Program.cs:line 38
How to repeat:
string strConn = "server=(address=xxx.xxx.xxx.xxa:3306,priority=100),(address=xxx.xxx.xxx.xxb:3306,priority=90),(address=xxx.xxx.xxx.xxc:3306,priority=80);uid=xxxx;password=xxxxx;connectiontimeout=60;defaultcommandtimeout=200;allowuservariables=True";
ParallelOptions po = new ParallelOptions();
po.MaxDegreeOfParallelism = Environment.ProcessorCount;
Parallel.For(0, 1000, po, async j =>
{
Console.WriteLine(j);
try
{
using (var conn = new MySqlConnection(strConn))
{
await conn.OpenAsync(); //Errors here.
await conn.CloseAsync();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
}
});
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.053 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: When multiple hosts are specified in connection string and connected to DB in parallel, the following errors occur intermittently. ------------------------------------------------------------------------- Results from .NET Core 3.1. Error NO 1. Object reference not set to an instance of an object. at MySql.Data.Failover.FailoverManager.AttemptConnection(MySqlConnection connection, String originalConnectionString, String& connectionString, Boolean mySqlPoolManager) at MySql.Data.MySqlClient.MySqlConnection.Open() at System.Data.Common.DbConnection.OpenAsync(CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at ConsoleApp1.Program.<>c__DisplayClass0_0.<<Main>b__0>d.MoveNext() in Program.cs:line 38 Error No 2. Collection was modified; enumeration operation may not execute. at System.Collections.Generic.Dictionary`2.KeyCollection.Enumerator.MoveNext() at System.Data.Common.DbConnectionStringBuilder.get_ConnectionString() at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value) at MySql.Data.MySqlClient.MySqlConnection.Open() at System.Data.Common.DbConnection.OpenAsync(CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at ConsoleApp1.Program.<>c__DisplayClass0_0.<<Main>b__0>d.MoveNext() in Program.cs:line 38 Error No 3. Authentication to host 'xxx.xxx.xxx.xxx' for user 'xxxxx' using method 'mysql_native_password' failed with message: Access denied for user ''@'xxx.xxx.xxx.xxx' (using password: NO) at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex) at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket() at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset) at MySql.Data.MySqlClient.NativeDriver.Open() at MySql.Data.MySqlClient.Driver.Open() at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() at MySql.Data.MySqlClient.MySqlPool.GetConnection() at MySql.Data.MySqlClient.MySqlConnection.Open() at System.Data.Common.DbConnection.OpenAsync(CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at ConsoleApp1.Program.<>c__DisplayClass0_0.<<Main>b__0>d.MoveNext() in Program.cs:line 38 How to repeat: string strConn = "server=(address=xxx.xxx.xxx.xxa:3306,priority=100),(address=xxx.xxx.xxx.xxb:3306,priority=90),(address=xxx.xxx.xxx.xxc:3306,priority=80);uid=xxxx;password=xxxxx;connectiontimeout=60;defaultcommandtimeout=200;allowuservariables=True"; ParallelOptions po = new ParallelOptions(); po.MaxDegreeOfParallelism = Environment.ProcessorCount; Parallel.For(0, 1000, po, async j => { Console.WriteLine(j); try { using (var conn = new MySqlConnection(strConn)) { await conn.OpenAsync(); //Errors here. await conn.CloseAsync(); } } catch (Exception ex) { Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace); } });