Bug #6601 mysql_ping ok if DB up, segmentation fault if db was shut down
Submitted: 12 Nov 2004 20:35 Modified: 5 Jan 2005 14:44
Reporter: Kendal Loseke Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL++ Severity:S2 (Serious)
Version:4.0.20 OS:Linux (Fedora Core 1)
Assigned to: CPU Architecture:Any

[12 Nov 2004 20:35] Kendal Loseke
Description:
I'm using a timer and want to ping every x seconds, even if I don't have a current need to execute SQL.  Calls to mysql_ping() from C are fine if DB is available.  If I do mysqladmin shutdown on the MySQL server and my application iterates to the mysql_ping again, then I get a segmentation fault on the mysql_ping() call.  Everything works great as long as MySQL is running.

How to repeat:

connect to db like:
	DBconnection = mysql_init(NULL);     

	if (DBconnection == NULL)
	{
		cout  << "Error with mysql_init() in DBConnect  " << endl;
		exit(1);
	}

	if (mysql_real_connect(
		DBconnection,
		host_name.c_str(),
		User_Name.c_str(),
		Password.c_str(),
		db_name.c_str(),
		0,					/* port (use default) now 3306 instead of 0*/
		NULL,				/* socket (use default)  */
		0)					/* flags (none)  */
			== NULL)
	{
              /* Have trouble */
        }
        else
        {
                  /* connected ok */
         }

then comes my main loop  for my program:

while()
{
             if( x seconds have passed)
             {
                        		if (mysql_ping(DBconnection) == 0)
		                        {
                                                /* MySQL is up */
                                         }
                                       else
                                          {
                                                   /* MySQL is down but I get a SEGMENTATION FAULT
                                                     on the mysql_ping call before I get here. */
                                          }
              }
.
.
.
}

Suggested fix:
Fix the client api call:
 mysql_ping(connection) 
to return a non zero value when it can't talk to the MySQL server.
[5 Jan 2005 14:39] Hartmut Holzgraefe
small testing example

Attachment: bug6601.c (text/plain), 385 bytes.

[5 Jan 2005 14:44] Hartmut Holzgraefe
I was not able to reproduce the crash with mysql_ping() using the attached
short test program. (tested on SuSE Linux 9.0)
[7 Jan 2005 16:43] Kendal Loseke
We discovered that our trouble was caused by a bug in the debugger for kdevelop.  When running normal (without debugger) all was fine.  Sorry to have wasted your time.

Kendal