Bug #88242 | autoReconnect and socketTimeout JDBC option makes wrong order of client packet | ||
---|---|---|---|
Submitted: | 27 Oct 2017 1:16 | Modified: | 22 Nov 2017 23:39 |
Reporter: | Seunguck Lee | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / J | Severity: | S1 (Critical) |
Version: | 5.1.41, 5.1.44 | OS: | Any |
Assigned to: | Filipe Silva | CPU Architecture: | Any |
[27 Oct 2017 1:16]
Seunguck Lee
[27 Oct 2017 1:17]
Seunguck Lee
Test case code
Attachment: ReqResMismatch.java (application/octet-stream, text), 1.65 KiB.
[27 Oct 2017 10:10]
MySQL Verification Team
== 5.1.44 with MySQL Server 5.7.20 [umshastr@hod03]~/bugs: java -cp '.:mysql-connector-java-5.1.44/mysql-connector-java-5.1.44-bin.jar' ReqResMismatch Fri Oct 27 11:23:29 CEST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. >> Query-1, key(1) : exception : Communications link failure The last packet successfully received from the server was 2,013 milliseconds ago. The last packet sent successfully to the server was 2,003 milliseconds ago. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure . >> Query-1, key(3) : exception : Communications link failure The last packet successfully received from the server was 2,003 milliseconds ago. The last packet sent successfully to the server was 2,003 milliseconds ago. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure . >> Query-1, key(5) : exception : Communications link failure The last packet successfully received from the server was 2,003 milliseconds ago. The last packet sent successfully to the server was 2,003 milliseconds ago. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure . >> Query-1, key(7) : exception : Communications link failure The last packet successfully received from the server was 2,003 milliseconds ago. The last packet sent successfully to the server was 2,003 milliseconds ago. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure . >> Query-1, key(9) : exception : Communications link failure The last packet successfully received from the server was 2,002 milliseconds ago. The last packet sent successfully to the server was 2,002 milliseconds ago. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure . >> Query-1, key(11) : exception : Communications link failure The last packet successfully received from the server was 2,001 milliseconds ago. The last packet sent successfully to the server was 2,001 milliseconds ago. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure . >> Query-1, key(13) : exception : Communications link failure The last packet successfully received from the server was 2,001 milliseconds ago. The last packet sent successfully to the server was 2,001 milliseconds ago. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure >> Query-2, key(14) : exception : ResultSet is from UPDATE. No Data. >> Query-1 : found mismatch : 15 ==> 14
[29 Oct 2017 5:04]
MySQL Verification Team
Hello Seunguck Lee, Thank you for the report and test case. Observed with 5.1.44. Thanks, Umesh
[29 Oct 2017 9:20]
DONGCHAN SUNG
Hi~ To prevent similar risks, we add new jdbc parameter "reconnectForceNew" and testing. >> https://github.com/mysql/mysql-connector-j/compare/release/5.1...gywndi:release/5.1 I do not think there is a reason to use a socket that the client determined was broken. And I hope that this unintended behavior of JDBC does not cause the MySQL server to lose trust. Check this and solve this problem please. :-) Thanks. Chan.
[29 Oct 2017 21:50]
Sveta Smirnova
Check also bug #88232 about similar issue.
[30 Oct 2017 8:16]
DONGCHAN SUNG
Hi~ I also checked MariaDB connector/j. But there's no problem. If there is any problem include 'socketTimeout', they only close the connection socket and process a new connection at the next query. I still can not understand why the connection marked as failure is needed to exectue next query. Thanks. Chan.
[3 Nov 2017 2:13]
Seunguck Lee
We have tested this case with MAX_EXECUTION_TIME hint and Statement.setQueryTimeout(). With both options, packet mismatch is not found during simple test case (which I have attached). But real service case (A lot of queries and system load), both options are not helpful. Both options are work only the query processing time is exceed specific time. But on heavy traffic server, actual query execution time is not so long, even queries are not logged in slow query log file (long_query_time=0.5). But response time on jdbc side of these queries are over 10 seconds. Are there any other options we should check ?
[22 Nov 2017 23:39]
Daniel So
Posted by developer: Added the following entry to the Connector/J 5.1.45 changelog: "Normally, when the socketTimeout option has been set and a socket timeout occurs on the client side, the server may continue working and returning query results. At the next query executed after the timeout, Connector/J first clears the socket input stream and then sends a ping request to the server. However, an error occurred if the autoReconnect option was set to true and, after reconnection, a new query was executed by Connector/J, and the results from the previous queries arrived before Connector/J sent its ping request to the server, in which case the old packages might be mistaken as results for the new query. This fix corrects the issue by forcibly closing the network resources after a communication or IO exception. The next statement execution recreates the IO stream if autoReconnect=true; otherwise, the connection stays closed."