Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ad46620

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

File tree

Expand file treeCollapse file tree

3 files changed

+48
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+48
-9
lines changed
Open diff view settings
Collapse file

‎CHANGES‎

Copy file name to clipboardExpand all lines: CHANGES
+2Lines 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

Collapse file

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

Copy file name to clipboardExpand all lines: src/main/user-impl/java/com/mysql/cj/jdbc/StatementImpl.java
+4-9Lines 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

Collapse file

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

Copy file name to clipboardExpand all lines: src/test/java/testsuite/regression/StatementRegressionTest.java
+42Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.