Bug #4906 ByteFX: mysqld bounce kills mono
Submitted: 5 Aug 2004 4:35 Modified: 8 Sep 2004 0:46
Reporter: Keith Dreibelbis Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:ByteFX 0.76, mono 1.0, mysqld 4.1.3 OS:Linux (linux)
Assigned to: Reggie Burnett CPU Architecture:Any

[5 Aug 2004 4:35] Keith Dreibelbis
Description:
When a mysqld restarts, something (in ByteFX?) causes mono to crash.  It occurs exactly when the next query is performed, after the mysqld has bounced.  Here is a simple ByteFX-based client that can demonstrate it (though just about any client should):

using System;
using ByteFX.Data.MySqlClient;

namespace foo {

	public class SimpleQuery {

		private static string connectionString = "Database=test;Data Source=localhost";

		private const string DROP_FOO = "DROP TABLE foo";
		private const string CREATE_FOO = "CREATE TABLE foo (id int, blah text)";		
		private const string INSERT_FOO = "INSERT INTO foo VALUES ({0}, '{1}')";		

		public static int Main(string[] argv) {
			if (argv.Length < 2) {
				System.Console.WriteLine("need mysql userid and password");
			}
			System.Console.WriteLine("Using data src " + connectionString);
			connectionString += ";User ID=" + argv[0] + ";Password=" + argv[1];
			
			string msg;
			SimpleQuery sq = new SimpleQuery();
			try {
				sq.ExecuteNonQuery(DROP_FOO);
			}
			catch (Exception) {}
			sq.ExecuteNonQuery(CREATE_FOO);
			
			int cnt = 0;
			while ((msg = System.Console.ReadLine()) != null) {
				System.Console.WriteLine("Inserting: '" + msg + "'");
				try {
					sq.ExecuteNonQuery(String.Format(INSERT_FOO, cnt++, msg));
				}
				catch (Exception e) {
					System.Console.WriteLine("Exception caught: " + e);
				}
			}
			sq.ExecuteNonQuery(DROP_FOO);
			System.Console.WriteLine("bye");
			return 0;
		}	

		public SimpleQuery() { }

	 	public int ExecuteNonQuery(string cmd)
		{
	         int rowsAffected;
	         MySqlConnection myConnection = new MySqlConnection(connectionString);
	         myConnection.Open();
	         MySqlCommand myCommand = new MySqlCommand(cmd, myConnection);
	         rowsAffected = myCommand.ExecuteNonQuery();
	         myConnection.Close();
	         return rowsAffected;
     	}		                                                                 		
	}
}

How to repeat:
Compile and run the above, passing in your localhost mysql username and password. (or change the data source if necessary)

% mono ./test.exe user pass
Using data src Database=test;Data Source=localhost
some value
Inserting: 'some value'
another row to be inserted
Inserting: 'another row to be inserted'
(verify that these got inserted into table "foo")
(now go to a root window and run "/etc/init.d/mysql restart".  wait for mysql to bounce fully.)
one more time
Inserting: 'one more time'
Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS
Aborted
%

Suggested fix:
Given that a SIGABRT occurs, it's possible that this is mono's bug, and not ByteFX's.  If that turns out to be the case, feel free to close this and I'll submit it to mono instead.

Don't know if this is helpful, but here's what gdb says after the crash:

Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS 
Program received signal SIGABRT, Aborted.
[Switching to Thread -173646928 (LWP 32610)]
0x00953402 in ?? ()
(gdb) where
#0  0x00953402 in ?? ()
#1  0x00a6ae49 in raise () from /lib/tls/libc.so.6
#2  0x00a6c872 in abort () from /lib/tls/libc.so.6
#3  0x004fba2c in GC_push_all_stack () from /usr/lib/libmono.so.0
#4  0x004f1481 in mono_escape_uri_string () from /usr/lib/libmono.so.0
#5  0x004f187f in mono_escape_uri_string () from /usr/lib/libmono.so.0
#6  0x004f1a17 in mono_escape_uri_string () from /usr/lib/libmono.so.0
#7  0x004f63f5 in mono_escape_uri_string () from /usr/lib/libmono.so.0
#8  0x004f64bd in mono_escape_uri_string () from /usr/lib/libmono.so.0
#9  0x004f667f in mono_escape_uri_string () from /usr/lib/libmono.so.0
#10 0x004f55b5 in mono_escape_uri_string () from /usr/lib/libmono.so.0
#11 0x0047a1e1 in mono_store_remote_field_new () from /usr/lib/libmono.so.0
#12 0x00477d8b in mono_array_new_specific () from /usr/lib/libmono.so.0
#13 0x00ec27d8 in ?? ()
#14 0x09678550 in ?? ()
#15 0xfffefeff in ?? ()
#16 0x0963afc8 in ?? ()
#17 0x0963afb0 in ?? ()
#18 0x0964fc70 in ?? ()
#19 0xffffffff in ?? ()
#20 0xffffffff in ?? ()
#21 0xffffffff in ?? ()
#22 0xf5a6559c in ?? ()
---Type <return> to continue, or q <return> to quit---
#23 0x00ec27b4 in ?? ()
#24 0xf5a655d0 in ?? ()
#25 0x00f5b6ef in ?? ()
#26 0x09678550 in ?? ()
#27 0xfffefeff in ?? ()
#28 0x00000000 in ?? ()
(gdb)
[7 Sep 2004 19:48] Keith Dreibelbis
This appears to be fixed in the latest mono CVS.
[7 Sep 2004 19:50] Keith Dreibelbis
... and so, someone should close this bug (since I cannot :)
[8 Sep 2004 0:46] Reggie Burnett
User  reported back that recent version of Mono fixed problem.