Bug #46178 MySql server crashes (supposedly when too many changes in transaction)
Submitted: 14 Jul 2009 17:18 Modified: 4 Sep 2009 23:14
Reporter: Pavel Bazanov Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:5.1.36 OS:Any
Assigned to: CPU Architecture:Any
Tags: big transaction, IOException, SocketException, unhandled exception in mysqld.exe

[14 Jul 2009 17:18] Pavel Bazanov
Description:
First, see the code in How to repeat section.

if deleteOldPrices is true, old prices are deleted from price list (there may be up to 200K price rows to delete - this may be important) and then after many (~1K) cycles "An unhandled Win32 exception occurred in mysqld.exe".
If deleteOldPrices is false, no exception is occurred. 
I think it's somehow related that we make too many changes in one transaction, though I'm not sure.

Exception log:

--------------------------------------------------------------------------------EXCEPTION TYPE: MySql.Data.MySqlClient.MySqlException
MESSAGE: Fatal error encountered during command execution.
STACK TRACE:
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) in C:\VCProjects\MySQL Connector .NET\MySql.Data\Provider\Source\command.cs:line 440
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() in C:\VCProjects\MySQL Connector .NET\MySql.Data\Provider\Source\command.cs:line 336
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() in C:\VCProjects\MySQL Connector .NET\MySql.Data\Provider\Source\command.cs:line 312
   at RA.WinForms.AddPricesForm.ImportPrice(String filename) in C:\VCProjects\Alex\RA\RA\WinForms\AddPricesForm.cs:line 384

INNER EXCEPTION INFORMATION:
EXCEPTION TYPE: MySql.Data.MySqlClient.MySqlException
MESSAGE: Fatal error encountered attempting to read the resultset.
STACK TRACE:
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult() in C:\VCProjects\MySQL Connector .NET\MySql.Data\Provider\Source\datareader.cs:line 910
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) in C:\VCProjects\MySQL Connector .NET\MySql.Data\Provider\Source\command.cs:line 423

INNER EXCEPTION INFORMATION:
EXCEPTION TYPE: MySql.Data.MySqlClient.MySqlException
MESSAGE: Reading from the stream has failed.
STACK TRACE:
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket() in C:\VCProjects\MySQL Connector .NET\MySql.Data\Provider\Source\MySqlStream.cs:line 203
   at MySql.Data.MySqlClient.MySqlStream.OpenPacket() in C:\VCProjects\MySQL Connector .NET\MySql.Data\Provider\Source\MySqlStream.cs:line 161
   at MySql.Data.MySqlClient.NativeDriver.ReadResult(UInt64& affectedRows, Int64& lastInsertId) in C:\VCProjects\MySQL Connector .NET\MySql.Data\Provider\Source\NativeDriver.cs:line 534
   at MySql.Data.MySqlClient.MySqlDataReader.GetResultSet() in C:\VCProjects\MySQL Connector .NET\MySql.Data\Provider\Source\datareader.cs:line 822
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult() in C:\VCProjects\MySQL Connector .NET\MySql.Data\Provider\Source\datareader.cs:line 865

INNER EXCEPTION INFORMATION:
EXCEPTION TYPE: System.IO.IOException
MESSAGE: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
STACK TRACE:
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.IO.BufferedStream.ReadByte()
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket() in C:\VCProjects\MySQL Connector .NET\MySql.Data\Provider\Source\MySqlStream.cs:line 187

INNER EXCEPTION INFORMATION:
EXCEPTION TYPE: System.Net.Sockets.SocketException
MESSAGE: An existing connection was forcibly closed by the remote host
STACK TRACE:
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--------------------------------------------------------------------------------

MySql server error log entry:

--------------------------------------------------------------------------------InnoDB: Assertion failure in thread 1048 in file .\row\row0mysql.c line 1534
InnoDB: Failing assertion: index->type & DICT_CLUSTERED
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.1/en/forcing-recovery.html
InnoDB: about forcing recovery.
090714 21:44:43 - mysqld got exception 0xc0000005 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=183500800
read_buffer_size=65536
max_used_connections=7
max_threads=100
threads_connected=5
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 211831 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd: 0x115f5ff0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
InnoDB: Thread 3680 stopped in file .\os\os0sync.c line 271
006B7146    mysqld.exe!row_unlock_for_mysql()[row0mysql.c:1534]
006BF358    mysqld.exe!row_search_for_mysql()[row0sel.c:4090]
006ABED0    mysqld.exe!ha_innobase::index_read()[ha_innodb.cc:4445]
0043ADB9    mysqld.exe!handler::index_read_map()[handler.h:1390]
0044629A    mysqld.exe!handler::index_read_idx_map()[handler.cc:4262]
00542707    mysqld.exe!write_record()[sql_insert.cc:1401]
00547CED    mysqld.exe!mysql_insert()[sql_insert.cc:812]
004B67FE    mysqld.exe!wait_if_global_read_lock()[lock.cc:1525]
00720065    mysqld.exe!flst_insert_after()[fut0lst.c:181]
00732D0F    mysqld.exe!__set_flsgetvalue()[tidtable.c:288]
00732EBB    mysqld.exe!_getptd_noexit()[tidtable.c:633]
00733CE2    mysqld.exe!write_string()[output.c:2570]
0073461D    mysqld.exe!_output_l()[output.c:2260]
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 115FFBA0=INSERT IGNORE INTO manprice SET ManufacturerID = 24, SupplierID = 6, PartN = 'TYREBS205/65VR16B390', Description = '205/65R16 BRIDGESTONE B390TTL', Price = 506 ON DUPLICATE KEY UPDATE Description = IF(Description REGEXP '[^-a-zA-Z0-9 *()+=,.<>/]{3,}' OR Description IS NULL OR LENGTH(Description) < 3, '205/65R16 BRIDGESTONE B390TTL', Description), Price = 506
thd->thread_id=72
thd->killed=NOT_KILLED
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
InnoDB: Thread 1036 stopped in file .\sync\sync0arr.c line 337
InnoDB: Thread 2924 stopped in file .\os\os0sync.c line 271
InnoDB: Thread 1744 stopped in file .\handler\ha_innodb.cc line 2262
--------------------------------------------------------------------------------

How to repeat:
var trx = conn.BeginTransaction(IsolationLevel.ReadCommitted);
command.Transaction = trx;

if (deleteOldPrices)
{
	command.CommandText = "DELETE FROM manprice WHERE ManufacturerID = ?ManufacturerID AND SupplierID = ?SupplierID";
	command.Parameters.AddWithValue("?ManufacturerID", manufacturerID);
	command.Parameters.AddWithValue("?SupplierID", supplierID);
	command.ExecuteNonQuery();
}

for (int i = 1; i <= records; i++)
{
	if(table[i, 1] == null || table[i, 3] == null)
	{
		foundEmptyPartNorPrice = true;
		continue;
	}

	string partN = table[i, 1].ToString();
	string description = Convert.ToString(table[i, 2]);
	object price = table[i, 3];
	double weight = Converter.ToDouble(table[i, 4]);

	if (!addWeightOnly) // DEFAULT OR ONLY NEW PART NUMBERS
	{
		command.CommandText = 
			"INSERT IGNORE INTO manprice SET ManufacturerID = ?ManufacturerID, SupplierID = ?SupplierID, " + 
			"PartN = ?PartN, Description = ?Description, Price = ?Price ";
		if (!addOnlyNew)
		{
			command.CommandText +=
				"ON DUPLICATE KEY UPDATE " +
				"Description = IF(Description REGEXP '[^-a-zA-Z0-9 *()+=,.<>/]{3,}' OR Description IS NULL OR LENGTH(Description) < 3, ?Description, Description), " + 
				"Price = ?Price";
		}
		command.Parameters.Clear();
		command.Parameters.AddWithValue("?ManufacturerID", manufacturerID);
		command.Parameters.AddWithValue("?SupplierID", supplierID);
		command.Parameters.AddWithValue("?PartN", partN);
		command.Parameters.AddWithValue("?Description", description);
		command.Parameters.AddWithValue("?Price", price);

		// WE FALL HERE AFTER MANY "FOR" CYCLES !!!!!!!!!!!!!!!!!!!!

		command.ExecuteNonQuery();
	}

	if (weight != 0)
	{
		command.Parameters.Clear();
		command.CommandType = CommandType.StoredProcedure;
		command.CommandText = "AddWeight";
		command.Parameters.Add("?OverwriteUnchecked", MySqlDbType.Bit).Value = !chkAddOnlyNewWeights.Checked;
		command.Parameters.Add("?ManufacturerID_", MySqlDbType.Int32).Value = manufacturerID;
		command.Parameters.Add("?PartN_", MySqlDbType.VarChar).Value = partN;
		command.Parameters.Add("?Weight_", MySqlDbType.Double).Value = weight;
		command.ExecuteNonQuery();
		command.CommandType = CommandType.Text;
	}
}

trx.Commit();
[14 Jul 2009 17:29] Pavel Bazanov
fixed tags
[14 Jul 2009 17:53] Miguel Solorzano
Thank you for the bug report. Could you please provide a dump file of the tables involved with create and insert statements?. Thanks in advance.
[15 Jul 2009 5:47] Shane Bester
this is a duplicate of bug #45357
[16 Jul 2009 11:25] Pavel Bazanov
Where can I download 5.1.37 to test whether this bug is fixed?
[4 Sep 2009 23:14] Pavel Bazanov
The bug doesn't appear in 5.1.38