Commit a098f46
committed
Bug #17309863 AUTO RECONNECT DOES NOT WORK WITH 5.6 LIBMYSQLCLIENT
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.1 parent 752f93f commit a098f46
2 files changed
+68
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
724 | 724 | | |
725 | 725 | | |
726 | 726 | | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
727 | 741 | | |
728 | 742 | | |
729 | 743 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19301 | 19301 | | |
19302 | 19302 | | |
19303 | 19303 | | |
| 19304 | + | |
| 19305 | + | |
| 19306 | + | |
| 19307 | + | |
| 19308 | + | |
| 19309 | + | |
| 19310 | + | |
| 19311 | + | |
| 19312 | + | |
| 19313 | + | |
| 19314 | + | |
| 19315 | + | |
| 19316 | + | |
| 19317 | + | |
| 19318 | + | |
| 19319 | + | |
| 19320 | + | |
| 19321 | + | |
| 19322 | + | |
| 19323 | + | |
| 19324 | + | |
| 19325 | + | |
| 19326 | + | |
| 19327 | + | |
| 19328 | + | |
| 19329 | + | |
| 19330 | + | |
| 19331 | + | |
| 19332 | + | |
| 19333 | + | |
| 19334 | + | |
| 19335 | + | |
| 19336 | + | |
| 19337 | + | |
| 19338 | + | |
| 19339 | + | |
| 19340 | + | |
| 19341 | + | |
| 19342 | + | |
| 19343 | + | |
| 19344 | + | |
| 19345 | + | |
| 19346 | + | |
| 19347 | + | |
| 19348 | + | |
| 19349 | + | |
| 19350 | + | |
| 19351 | + | |
| 19352 | + | |
| 19353 | + | |
| 19354 | + | |
19304 | 19355 | | |
19305 | 19356 | | |
19306 | 19357 | | |
| |||
19573 | 19624 | | |
19574 | 19625 | | |
19575 | 19626 | | |
| 19627 | + | |
| 19628 | + | |
| 19629 | + | |
19576 | 19630 | | |
19577 | 19631 | | |
19578 | 19632 | | |
| |||
0 commit comments