Bug #11796 Access Violation in when stopping MySQL Server while MySQLAdministrator running
Submitted: 7 Jul 2005 13:42 Modified: 20 Nov 2005 4:36
Reporter: Emmanuel KARTMANN Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.1.12/BK source OS:Windows (Windows XP, Windows 2000)
Assigned to: Jim Winstead CPU Architecture:Any

[7 Jul 2005 13:42] Emmanuel KARTMANN
Description:
When I stop MySQL Server while the MySQLAdministrator is connected to the server, I have a access violation and a MySQL server crash (I don't know if the database is properly closed/flushed...).

I'm using MySQL Server 4.1.11 on Windows XP (or Windows 2000, or Windows 2003 Server), MySQLAdminstrator 1.0.20 on Windows XP.

The call stack is:
>	mysqld-debug.exe!mysqld_show(THD * thd=0x00dfdb10, const char * wild=0x00000000, show_var_st * variables=0x007f7a58, enum_var_type value_type=OPT_GLOBAL, _RTL_CRITICAL_SECTION * mutex=0x00918fac)  Line 1886 + 0x6	C++
 	mysqld-debug.exe!mysql_execute_command(THD * thd=0x00dfdb10)  Line 3006 + 0x48	C++
 	mysqld-debug.exe!mysql_parse(THD * thd=0x00dfdb10, char * inBuf=0x00e070d8, unsigned int length=11)  Line 4186 + 0x9	C++
 	mysqld-debug.exe!dispatch_command(enum_server_command command=COM_QUERY, THD * thd=0x00dfdb10, char * packet=0x00dff029, unsigned int packet_length=12)  Line 1505 + 0x1d	C++
 	mysqld-debug.exe!do_command(THD * thd=0x00dfdb10)  Line 1318 + 0x31	C++
 	mysqld-debug.exe!handle_one_connection(void * arg=0x00dfdb10)  Line 1050 + 0x9	C++
 	mysqld-debug.exe!pthread_start(void * param=0x00db9d70)  Line 63 + 0x7	C
 	mysqld-debug.exe!_threadstart(void * ptd=0x00db9da8)  Line 196 + 0xd	C
 	kernel32.dll!7c80b50b() 	

The source code is:

      case SHOW_SLAVE_RUNNING:
      {
	pthread_mutex_lock(&LOCK_active_mi);
	end= strmov(buff, (active_mi->slave_running &&
1886 =>			   active_mi->rli.slave_running) ? "ON" : "OFF"); 
	pthread_mutex_unlock(&LOCK_active_mi);
	break;
      }

Under debugger, variable "active_mi" is NULL (dereferencing it is causing the server crash...).

How to repeat:
 * Start MySQL Server
 * Start MySQLAdminstrator and click on "Health" option.
   (I guess this will call mysqld_show on a regular basis, but if the server is stopping, then mysqld_show will crash!).
 * Stop MySQL Server (NET STOP MYSQL).

=> Crash occurs (not always, but most of the time!).

Suggested fix:
Check active_mi value before dereferencing the pointer:

	pthread_mutex_lock(&LOCK_active_mi);
	if (active_mi != NULL)
	{
		end= strmov(buff, (active_mi->slave_running &&
			   active_mi->rli.slave_running) ? "ON" : "OFF"); 
	}
	pthread_mutex_unlock(&LOCK_active_mi);
[7 Jul 2005 19:39] MySQL Verification Team
Thank you for the bug report I was able to repeat. However looks
to me that it was already reported and I will back with the number
bug report.
[22 Jul 2005 2:23] Jim Winstead
This happens because we call end_slave() before we have shut down all of the connections to the server. I'm looking into whether we just need to fix the ordering of that.
[9 Aug 2005 1:04] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/28046
[15 Aug 2005 22:19] Jim Winstead
Fixed in 4.1.14 and 5.0.12.
[17 Aug 2005 18:20] Paul DuBois
Noted in 4.1.14, 5.0.12 changelogs.
[2 Sep 2005 13:04] Emmanuel KARTMANN
Sorry but the bug is still present in version 4.1.14; when I stop MySQL while MySQL Administrator is running, I still get the same crash.

Call stack is:

>	mysqld-debug.exe!mysqld_show(THD * thd=0x011ac010, const char * wild=0x00000000, show_var_st * variables=0x007c6a74, enum_var_type value_type=OPT_GLOBAL, _RTL_CRITICAL_SECTION * mutex=0x009547b8)  Line 1918 + 0x6	C++
 	mysqld-debug.exe!mysql_execute_command(THD * thd=0x011ac010)  Line 3068 + 0x48	C++
 	mysqld-debug.exe!mysql_parse(THD * thd=0x011ac010, char * inBuf=0x011b54b8, unsigned int length=11)  Line 4278 + 0x9	C++
 	mysqld-debug.exe!dispatch_command(enum_server_command command=COM_QUERY, THD * thd=0x011ac010, char * packet=0x011ad3f9, unsigned int packet_length=12)  Line 1500 + 0x1d	C++
 	mysqld-debug.exe!do_command(THD * thd=0x011ac010)  Line 1313 + 0x31	C++
 	mysqld-debug.exe!handle_one_connection(void * arg=0x011ac010)  Line 1045 + 0x9	C++
 	mysqld-debug.exe!pthread_start(void * param=0x00df4130)  Line 63 + 0x7	C
 	mysqld-debug.exe!_threadstart(void * ptd=0x00df42d0)  Line 173 + 0xd	C
 	kernel32.dll!7c80b50b() 	

The source code is:

      case SHOW_SLAVE_RUNNING:
      {
	pthread_mutex_lock(&LOCK_active_mi);
	end= strmov(buff, (active_mi->slave_running &&
1918=>			   active_mi->rli.slave_running) ? "ON" : "OFF");
	pthread_mutex_unlock(&LOCK_active_mi);
	break;
      }

Under debugger, variable "active_mi" is still NULL (dereferencing it is causing the
server crash...).

E.
[9 Sep 2005 15:47] MySQL Verification Team
Debug 4.0.15 server still crash:

 	ntdll.dll!7c901010() 	
>	mysqld-debug.exe!mysqld_show(THD * thd=0x02fd4750, const char * wild=0x00000000, show_var_st * variables=0x008237a4, enum_var_type value_type=OPT_GLOBAL, _RTL_CRITICAL_SECTION * mutex=0x00943224)  Line 1930	C++
 	mysqld-debug.exe!mysql_execute_command(THD * thd=0x02fd4750)  Line 3085 + 0x48	C++
 	mysqld-debug.exe!mysql_parse(THD * thd=0x02fd4750, char * inBuf=0x02fe7920, unsigned int length=11)  Line 4295 + 0x9	C++
 	mysqld-debug.exe!dispatch_command(enum_server_command command=COM_QUERY, THD * thd=0x02fd4750, char * packet=0x02fdf871, unsigned int packet_length=12)  Line 1500 + 0x1d	C++
 	mysqld-debug.exe!do_command(THD * thd=0x02fd4750)  Line 1313 + 0x31	C++
 	mysqld-debug.exe!handle_one_connection(void * arg=0x02fd4750)  Line 1045 + 0x9	C++
 	mysqld-debug.exe!pthread_start(void * param=0x02fd0958)  Line 63 + 0x7	C
 	mysqld-debug.exe!_threadstart(void * ptd=0x00f2edb0)  Line 196 + 0xd	C
 	kernel32.dll!7c80b50b() 	
 	kernel32.dll!7c8399f3() 	

c:\mysql\bin>mysqld-debug --standalone --console
050909 12:43:59  InnoDB: Started; log sequence number 0 55993
mysqld-debug: ready for connections.
Version: '4.1.15-debug'  socket: ''  port: 3306  Source distribution
050909 12:44:21 [Note] mysqld-debug: Normal shutdown

050909 12:44:23 [Warning] mysqld-debug: Forcing close of thread 3  user: 'root'

050909 12:44:23 [Warning] mysqld-debug: Forcing close of thread 1  user: 'root'
[1 Nov 2005 19:47] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/31755
[18 Nov 2005 16:08] Jim Winstead
Fixed in 4.1.16 and 5.0.17.
[20 Nov 2005 4:36] Paul DuBois
Noted in 4.1.16, 5.0.17 changelogs.