Bug #73107 error code of mysql_real_query
Submitted: 25 Jun 2014 6:50 Modified: 26 Jun 2014 6:27
Reporter: USER USER Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / C Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: CPU Architecture:Any
Tags: error code of mysql_real_query

[25 Jun 2014 6:50] USER USER
Description:
MYSQL_OPT_RECONNECT is set

call mysql_real_query(...)  return ERROR 2013 - Lost connection to MySQL server during query

after

call mysql_real_query(...)  return ERROR 2003 - Can't connect to MySQL server

How to repeat:
MYSQL_OPT_RECONNECT is set

call mysql_real_query(...)  return ERROR 2013 - Lost connection to MySQL server during query

after

call mysql_real_query(...)  return ERROR 2003 - Can't connect to MySQL server
[25 Jun 2014 10:40] MySQL Verification Team
not sure of connector/c versions, but maybe:
http://bugs.mysql.com/bug.php?id=70026
[25 Jun 2014 15:29] USER USER
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include <mysql.h>
#include <errmsg.h>

/*
 Net UP 
 RUN APP
 
 k[0], -OK- 
 k[1], -OK- 
  Net DOWN, TimeOut
 k[2],  ERROR [2013]
  TimeOut
 k[3],  ERROR [2003]
  Net UP - Reconnect
 k[4], -OK- 
 k[5], -OK- 
  Net DOWN , TimeOut
 k[6],  ERROR [2013]
  Net UP - Reconnect
 k[7], -OK- 
  Net DOWN, TimeOut
 k[8],  ERROR [2013] 
  Net UP - Reconnect
 k[9], -OK- 
 
*/

int main(void)
{
  MYSQL *MySqLHandlE = NULL;
  my_bool do_reconnect = 1;
  unsigned int CONNECT_TIMEOUT = 10;
  unsigned int READ_TIMEOUT = 10;
  unsigned int WRITE_TIMEOUT = 10;
  
  unsigned char k = 0;
  
  mysql_library_init(0, NULL, NULL);
  MySqLHandlE = mysql_init(NULL);
  mysql_options(MySqLHandlE, MYSQL_OPT_RECONNECT, &do_reconnect);
  mysql_options(MySqLHandlE, MYSQL_OPT_CONNECT_TIMEOUT, &CONNECT_TIMEOUT);
  mysql_options(MySqLHandlE, MYSQL_OPT_READ_TIMEOUT, &READ_TIMEOUT);
  mysql_options(MySqLHandlE, MYSQL_OPT_WRITE_TIMEOUT, &WRITE_TIMEOUT);
  mysql_real_connect(MySqLHandlE, "IP", "USER", "PASS", "DB", 3306, NULL, CLIENT_NO_SCHEMA | CLIENT_REMEMBER_OPTIONS | CLIENT_MULTI_STATEMENTS);

 k = 0;
 do
 {
  if(mysql_real_query(MySqLHandlE, "select 1 as `f0`", strlen("select 1 as `f0`")) == 0)
  {
   mysql_free_result(mysql_store_result(MySqLHandlE));
   fprintf(stdout,"\n k[%d], -OK- \n", k);
  }
   else
   {
    fprintf(stdout,"\n k[%d],  ERROR [%d] \n", k, mysql_errno(MySqLHandlE));
   }
   
  sleep(5);
 }
 while(k++ < 9);

  mysql_close(MySqLHandlE); MySqLHandlE = NULL;
  mysql_library_end();
  
 return(0);
}
[26 Jun 2014 6:27] MySQL Verification Team
Thank you for the report and test case.
Verified on latest build(5.6.20).

mysql-advanced-5.6.20]$ gcc bug73107.c -Wall -g -o bug73107 -L /data/ushastry/server/mysql-advanced-5.6.20/lib/ -I /data/ushastry/server/mysql-advanced-5.6.20/include/ -lmysqlclient_r -lz -lm
[ushastry@cluster-repo mysql-advanced-5.6.20]$ ./bug73107

 k[0], -OK-

 k[1], -OK-

 k[2], -OK-

 k[3], -OK-

 k[4],  ERROR [2013]

 k[5],  ERROR [2003]

 k[6],  ERROR [2003]

 k[7],  ERROR [2003]

 k[8],  ERROR [2003]

 k[9], -OK-

 k[10], -OK-

 k[11], -OK-

Thanks,
Umesh