MySQL dotConnect Lockup/Infinite loop
Posted: Mon 11 Jan 2010 17:12
The following code sample creates what seems to be a recursive infinite loop. I suspect that when the connection exception occurs, it tries to close the connection and thus will tries to commit the open transaction, which fails and tries to close the connection, etc.
This happens on version 5.40.44.0. Can you please check if this is fixed in the current newest version? If so i will simply upgrade, however I'd like to avoid the upgrade process if the current version is fixed and just simply wait till a version with this bug fixed is released. Thank you.
This happens on version 5.40.44.0. Can you please check if this is fixed in the current newest version? If so i will simply upgrade, however I'd like to avoid the upgrade process if the current version is fixed and just simply wait till a version with this bug fixed is released. Thank you.
Code: Select all
///
/// Reproduce locked table bug for DevART MySQL
///
private void BugRepro()
{
try
{
var connectionStringBuilder = new MySqlConnectionStringBuilder
{
Host = "*",
UserId = "*",
Password = "*"
};
string cs = connectionStringBuilder.ToString();
string dataBaseName = "devartBugRepro";
string tableName = "testTable";
string setupSchema = "CREATE DATABASE `" + dataBaseName
+
@"`;
CREATE TABLE `"
+ dataBaseName + "`.`" + tableName
+
@"` (
`Id` int(11) NOT NULL auto_increment,
`Name` varchar(45) default NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB;";
string dropSchema = "DROP DATABASE `" + dataBaseName + "`";
using (var mysqlConn = new MySqlConnection(cs))
{
mysqlConn.Open();
using (MySqlCommand cmd = mysqlConn.CreateCommand())
{
cmd.CommandText = setupSchema;
cmd.ExecuteNonQuery();
var endSignal = new ManualResetEvent(false);
var readySignal = new ManualResetEvent(false);
var lockThread =
new Thread(
x =>
this.LockDB(endSignal,
readySignal,
cs,
dataBaseName,
tableName));
lockThread.Start();
readySignal.WaitOne(); // Wait for thread to signal us to go.
cmd.CommandText = "USE " + dataBaseName;
cmd.ExecuteNonQuery();
using (var itx = mysqlConn.BeginTransaction())
{
using (var transCmd = mysqlConn.CreateCommand())
{
transCmd.Transaction = itx;
transCmd.CommandText = "INSERT INTO `" + tableName
+
"` (`Id`, `Name`) VALUES (NULL, \"Nick\");";
transCmd.ExecuteNonQuery();
itx.Commit();
}
}
endSignal.Set();
cmd.CommandText = dropSchema;
cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception in BugRepro: " + ex);
}
}
///
/// Locks the DB.
///
///
/// The to end this thread.
///
///
/// Signal we have locked the table and are finished.
///
///
/// The connection string.
///
///
/// Name of the database.
///
///
/// Name of the table.
///
private void LockDB(WaitHandle endSignal,
WaitHandle readySignal,
string connectionString,
string dataBaseName,
string tableName)
{
try
{
using (var mysqlConn = new MySqlConnection(connectionString))
{
mysqlConn.Open();
using (MySqlCommand cmd = mysqlConn.CreateCommand())
{
cmd.CommandText = "USE " + dataBaseName;
cmd.ExecuteNonQuery();
cmd.CommandText = "LOCK TABLE " + tableName + " WRITE";
cmd.ExecuteNonQuery();
WaitHandle.SignalAndWait(readySignal, endSignal);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception in LockDB Thread: " + ex);
}
}