Random error System.Threading.ThreadAbortException on connector v8.2
Posted by:
Chris L
Date: November 24, 2023 01:41PM
I have an asp.net v4.7.2 website that uses mysql 5.7.42 and connector v6.2. The site has been running flawless for several years until I upgraded the connector version to the latest v8.2. Every few days, the MySqlConnection.Open() throws out System.Threading.ThreadAbortException in the following stacks.
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Monitor.ObjWait(Boolean exitContext, Int32 millisecondsTimeout, Object obj)
at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.SpinThenBlockingWait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.InternalWait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MySql.Data.MySqlClient.MySqlConnection.Open()
My connection string and codes are as follows. The error is thrown at line "myConnection.Open();".
"Datasource=xxxx;Database=xxx;User ID=xxx;Password=xxx;default command timeout=15;"
public DataTable ExecTable(string SPName, DbParameter[] pars)
{
DbConnection myConnection = new MySqlConnection(connection_string);
DbDataAdapter myCommand = GetDataAdapter(SPName, myConnection);
myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
if (pars != null)
myCommand.SelectCommand.Parameters.AddRange(pars);
DataSet result = new DataSet();
try
{
myConnection.Open();
myCommand.Fill(result);
}
catch (Exception ex)
{
if (myConnection is MySqlConnection)
MySqlConnection.ClearPool((MySqlConnection)myConnection);
throw ex;
}
finally
{
if (myConnection != null && myConnection.State == ConnectionState.Open)
myConnection.Close();
myConnection = null;
}
return result.Tables[0];
}
The error occurs once every few days, usually during high traffic period. Rebooting the server does not help this issue. The error occurs 2 minutes after the database call. Even through the default command timeout is set to 15 seconds, this error does not occur until 2 minutes later. Before that, there is no connection timeout error. When this error occurs, the following database calls result in the same error. The website can no longer open a new connection and stops functioning. I have to perform an IISRESET to bring the website online again.
When this happens, the database server does not have any error. The CPU and connection count are normal.
Anybody knows how to fix it?