Skip to content

Commit a9b61b0

Browse files
author
Arun Kuruvila
committed
Bug#17599258:- ERROR 1160 (08S01): GOT AN ERROR WRITING
COMMUNICATION PACKETS; FEDERATED TABLE Description:- Execution of FLUSH TABLES on a federated table which has been idle for wait_timeout (on the remote server) + tcp_keepalive_time, fails with an error, "ERROR 1160 (08S01): Got an error writing communication packets." Analysis:- During FLUSH TABLE execution the federated table is closed which will inturn close the federated connection. While closing the connection, federated server tries to communincate with the remote server. Since the connection was idle for wait_timeout(on the remote server)+ tcp_keepalive_time, the socket gets closed. So this communication fails because of broken pipe and the error is thrown. But federated connections are expected to reconnect silently. And also it cannot reconnect because the "auto_reconnect" variable is set to 0 in "mysql_close()". Fix:- Before closing the federated connection, in "ha_federated_close()", a check is added which will verify wheather the connection is alive or not. If the connection is not alive, then "mysql->net.error" is set to 2 which will indicate that the connetion is broken. Also the setting of "auto_reconnect" variable to 0 is delayed and is done after "COM_QUIT" command. NOTE:- For reproducing this issue, "tcp_keepalive_time" has to be set to a smaller value. This value is set in the "/proc/sys/net/ipv4/tcp_keepalive_time" file in Unix systems. So we need root permission for changing it, which can't be done through mtr test. So submitting the patch without mtr test.
1 parent 5a59bf7 commit a9b61b0

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

sql-common/client.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -3808,8 +3808,8 @@ void STDCALL mysql_close(MYSQL *mysql)
38083808
{
38093809
free_old_query(mysql);
38103810
mysql->status=MYSQL_STATUS_READY; /* Force command */
3811-
mysql->reconnect=0;
38123811
simple_command(mysql,COM_QUIT,(uchar*) 0,0,1);
3812+
mysql->reconnect=0;
38133813
end_server(mysql); /* Sets mysql->net.vio= 0 */
38143814
}
38153815
mysql_close_free_options(mysql);

storage/federated/ha_federated.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -1678,9 +1678,17 @@ int ha_federated::close(void)
16781678
DBUG_ENTER("ha_federated::close");
16791679

16801680
free_result();
1681-
1681+
16821682
delete_dynamic(&results);
1683-
1683+
1684+
/*
1685+
Check to verify wheather the connection is still alive or not.
1686+
FLUSH TABLES will quit the connection and if connection is broken,
1687+
it will reconnect again and quit silently.
1688+
*/
1689+
if (mysql && !vio_is_connected(mysql->net.vio))
1690+
mysql->net.error= 2;
1691+
16841692
/* Disconnect from mysql */
16851693
mysql_close(mysql);
16861694
mysql= NULL;

0 commit comments

Comments
 (0)