Skip to content

Commit ad46620

Browse files
committed
Fix for Bug#96900 (30355150), STATEMENT.CANCEL()CREATE A DATABASE
CONNECTION BUT DOES NOT CLOSE THE CONNECTION.
1 parent 4d19ea1 commit ad46620

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
Version 8.0.28
55

6+
- Fix for Bug#96900 (30355150), STATEMENT.CANCEL()CREATE A DATABASE CONNECTION BUT DOES NOT CLOSE THE CONNECTION.
7+
68
- Fix for Bug#104067 (33054827), No reset autoCommit after unknown issue occurs.
79
Thanks to Tingyu Wei for his contribution.
810

src/main/user-impl/java/com/mysql/cj/jdbc/StatementImpl.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,14 @@ public void cancel() throws SQLException {
289289
}
290290

291291
if (!this.isClosed && this.connection != null) {
292-
JdbcConnection cancelConn = null;
293-
java.sql.Statement cancelStmt = null;
292+
NativeSession newSession = null;
294293

295294
try {
296295
HostInfo hostInfo = this.session.getHostInfo();
297296
String database = hostInfo.getDatabase();
298297
String user = hostInfo.getUser();
299298
String password = hostInfo.getPassword();
300-
NativeSession newSession = new NativeSession(this.session.getHostInfo(), this.session.getPropertySet());
299+
newSession = new NativeSession(this.session.getHostInfo(), this.session.getPropertySet());
301300
newSession.connect(hostInfo, user, password, database, 30000, new TransactionEventHandler() {
302301
@Override
303302
public void transactionCompleted() {
@@ -313,12 +312,8 @@ public void transactionBegun() {
313312
} catch (IOException e) {
314313
throw SQLExceptionsMapping.translateException(e, this.exceptionInterceptor);
315314
} finally {
316-
if (cancelStmt != null) {
317-
cancelStmt.close();
318-
}
319-
320-
if (cancelConn != null) {
321-
cancelConn.close();
315+
if (newSession != null) {
316+
newSession.forceClose();
322317
}
323318
}
324319

src/test/java/testsuite/regression/StatementRegressionTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11898,4 +11898,46 @@ public void testBug85223() throws Exception {
1189811898
String value = this.rs.getString(1);
1189911899
assertEquals("LName", value);
1190011900
}
11901+
11902+
/**
11903+
* Test fix for Bug#96900 (30355150), STATEMENT.CANCEL()CREATE A DATABASE CONNECTION BUT DOES NOT CLOSE THE CONNECTION.
11904+
*
11905+
* @throws Exception
11906+
*/
11907+
@Test
11908+
public void testBug96900() throws Exception {
11909+
assumeTrue(versionMeetsMinimum(5, 6), "MySQL 5.6+ is required to run this test.");
11910+
11911+
Properties props = new Properties();
11912+
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
11913+
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
11914+
props.setProperty(PropertyKey.connectionAttributes.getKeyName(), "testBug96900:1");
11915+
11916+
Connection con = getConnectionWithProps(props);
11917+
Statement st = con.createStatement();
11918+
new Thread(() -> {
11919+
try {
11920+
st.executeQuery("SELECT SLEEP(600)");
11921+
} catch (Throwable e) {
11922+
e.printStackTrace();
11923+
}
11924+
}).start();
11925+
11926+
String attCountQuery = "SELECT COUNT(*) FROM performance_schema.session_connect_attrs WHERE attr_name = 'testBug96900'";
11927+
11928+
this.rs = this.stmt.executeQuery(attCountQuery);
11929+
this.rs.next();
11930+
assertEquals(1, this.rs.getInt(1));
11931+
11932+
st.cancel();
11933+
this.rs = this.stmt.executeQuery(attCountQuery);
11934+
this.rs.next();
11935+
assertEquals(1, this.rs.getInt(1));
11936+
11937+
con.close();
11938+
this.rs = this.stmt.executeQuery(attCountQuery);
11939+
this.rs.next();
11940+
assertEquals(0, this.rs.getInt(1));
11941+
}
11942+
1190111943
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy