-
Venkata Sidagam authored
Problem Statement: Automatic reconnection does not work for MySQL client programs linked with 5.6 libmysqlclient, even if MYSQL_OPT_RECONNECT is enabled. Analysis: When we have two connections (say con_1 and con_2) in which 'con_1' has auto-reconnect enabled. In such case if 'con_2' sends 'KILL <con_1 id>' (killing 'con_1'), then the server closes the socket for 'con_1'. After that when we send any query to 'con_1' it is failing with "Lost connection to MySQL server during query" error, even though auto-reconnect is enabled for 'con_1'. This is because send() which sends query might still succeed on client even though connection has been already closed on server. Since send() returns success at client side, client tries to recv() the data. Now client receives '0' means that the peer has closed the connection. Hence the query fails with the error mentioned above. Problem didn't exist in 5.5 and earlier versions because in them we tried to read-up all data remaining from previous command before sending new one to the server. As result we detected that connection was closed before query was sent and re-established connection. Fix: Check if socket is alive using vio_is_connected() call in case if auto-reconnect is enabled before sending query to server. If socket was disconnected by server set net->error to 2 so the socket on the client will be closed as well and reconnect will be initiated before sending the query. Reconnect doesn't make sense in case of COM_QUIT so skip the connection check for this command. Note: This fix doesn't solve the problem fully as bug still can occur if connection is killed exactly after this check and before query is sent. But this is acceptable since similar problem exists in 5.5. Also note that this patch might cause slight performance degradation, but it affects only auto-reconnect mode and therefore acceptable.
Venkata Sidagam authoredProblem Statement: Automatic reconnection does not work for MySQL client programs linked with 5.6 libmysqlclient, even if MYSQL_OPT_RECONNECT is enabled. Analysis: When we have two connections (say con_1 and con_2) in which 'con_1' has auto-reconnect enabled. In such case if 'con_2' sends 'KILL <con_1 id>' (killing 'con_1'), then the server closes the socket for 'con_1'. After that when we send any query to 'con_1' it is failing with "Lost connection to MySQL server during query" error, even though auto-reconnect is enabled for 'con_1'. This is because send() which sends query might still succeed on client even though connection has been already closed on server. Since send() returns success at client side, client tries to recv() the data. Now client receives '0' means that the peer has closed the connection. Hence the query fails with the error mentioned above. Problem didn't exist in 5.5 and earlier versions because in them we tried to read-up all data remaining from previous command before sending new one to the server. As result we detected that connection was closed before query was sent and re-established connection. Fix: Check if socket is alive using vio_is_connected() call in case if auto-reconnect is enabled before sending query to server. If socket was disconnected by server set net->error to 2 so the socket on the client will be closed as well and reconnect will be initiated before sending the query. Reconnect doesn't make sense in case of COM_QUIT so skip the connection check for this command. Note: This fix doesn't solve the problem fully as bug still can occur if connection is killed exactly after this check and before query is sent. But this is acceptable since similar problem exists in 5.5. Also note that this patch might cause slight performance degradation, but it affects only auto-reconnect mode and therefore acceptable.
Loading