Bug #96900 | statement.cancel()create a database connection but does not close the connection | ||
---|---|---|---|
Submitted: | 17 Sep 2019 8:43 | Modified: | 11 Dec 2021 16:27 |
Reporter: | beitian wang | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / J | Severity: | S2 (Serious) |
Version: | Versions 8.0.13-8.0.17 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[17 Sep 2019 8:43]
beitian wang
[26 Sep 2019 12:58]
MySQL Verification Team
Hello Beitian, Thank you for the report. regards, Umesh
[15 Apr 2020 2:22]
beitian wang
Add the method "newSession.getProtocol().getSocketConnection().forceClose()" in finally{} of StatementImpl.cancel()
[15 Apr 2020 2:22]
beitian wang
Add the method "newSession.getProtocol().getSocketConnection().forceClose()" in finally{} of StatementImpl.cancel()
[19 May 2021 0:50]
Charly Batista
The issue is that the two objects that are created to, theoretically, run the KILL command on MySQL are never used: ``` if (!this.isClosed && this.connection != null) { JdbcConnection cancelConn = null; java.sql.Statement cancelStmt = null; <...> } finally { if (cancelStmt != null) { cancelStmt.close(); } if (cancelConn != null) { cancelConn.close(); } } ``` But the object that is used is a "NativeSession" one: ``` NativeSession newSession = new NativeSession(this.session.getHostInfo(), this.session.getPropertySet()); newSession.connect(hostInfo, user, password, database, 30000, new TransactionEventHandler() { @Override public void transactionCompleted() { } @Override public void transactionBegun() { } }); newSession.sendCommand(new NativeMessageBuilder().buildComQuery(newSession.getSharedSendPacket(), "KILL QUERY " + this.session.getThreadId()), false, 0); setCancelStatus(CancelStatus.CANCELED_BY_USER); ``` It should either use the "JdbcConnection" and "Statement" objects or remove them and do the correct test and cleanup on the finally section. --- Charly
[11 Dec 2021 16:27]
Daniel So
Posted by developer: Added the following entry to the Connector/J 8.0.28 changelog: "A new session created for executing Statement.cancel() remained open after the Statement had been cancelled. With this fix, the session is closed after the Statement cancellation."