diff --git a/include/mysql_connection.h b/include/mysql_connection.h index b53ce9e7b..6fa7ba9e4 100644 --- a/include/mysql_connection.h +++ b/include/mysql_connection.h @@ -132,5 +132,6 @@ class MySQL_Connection { bool MultiplexDisabled(); void ProcessQueryAndSetStatusFlags(char *query_digest_text); void optimize(); + void close_mysql(); }; #endif /* __CLASS_MYSQL_CONNECTION_H */ diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index b15211dc7..0afc87bf4 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -57,6 +57,7 @@ static void * kill_query_thread(void *arg) { } char buf[100]; sprintf(buf,"KILL QUERY %lu", ka->id); + // FIXME: these 2 calls are blocking, fortunately on their own thread mysql_query(mysql,buf); mysql_close(mysql); __exit_kill_query_thread: diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index bcb8973ea..4ce649efd 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -173,12 +173,7 @@ MySQL_Connection::~MySQL_Connection() { // always decrease the counter __sync_fetch_and_sub(&MyHGM->status.server_connections_connected,1); async_free_result(); - if (send_quit) { - mysql_close(mysql); - } else { - mysql_close_no_command(mysql); - shutdown(fd, SHUT_RDWR); - } + close_mysql(); // this take care of closing mysql connection mysql=NULL; } // // FIXME: with the use of mysql client library , this part should be gone. @@ -1096,3 +1091,21 @@ void MySQL_Connection::optimize() { } } } + +// close_mysql() is a replacement for mysql_close() +// if avoids that a QUIT command stops forever +// FIXME: currently doesn't support encryption and compression +void MySQL_Connection::close_mysql() { + if (send_quit) { + char buff[5]; + mysql_hdr myhdr; + myhdr.pkt_id=0; + myhdr.pkt_length=1; + memcpy(buff, &myhdr, sizeof(mysql_hdr)); + buff[4]=0x01; + int fd=mysql->net.fd; + send(fd, buff, 5, MSG_NOSIGNAL); + } + mysql_close_no_command(mysql); + shutdown(fd, SHUT_RDWR); +}