Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-863] ensure socket state when having IOException
  • Loading branch information
rusher committed Jul 29, 2021
1 parent 4ea0eab commit 0f04e45
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Expand Up @@ -2046,6 +2046,7 @@ public SQLException handleIoException(Exception initialException) {
if (maxSizeError) {
mustReconnect = true;
}
if (initialException instanceof SocketTimeoutException) destroySocket();
}

if (mustReconnect && !explicitClosed) {
Expand Down
33 changes: 33 additions & 0 deletions src/test/java/org/mariadb/jdbc/ConnectionTest.java
Expand Up @@ -812,6 +812,39 @@ public void connectionUnexpectedClose() throws SQLException {
}
}

@Test
public void ensureSocketTimeoutState() throws Throwable {

Statement stmt = sharedConnection.createStatement();
stmt.execute("DROP TABLE IF EXISTS ensureSocketTimeoutState");
stmt.execute("CREATE TABLE ensureSocketTimeoutState(id int auto_increment primary key)");
stmt.execute("INSERT INTO ensureSocketTimeoutState VALUES (1), (3), (5), (7), (9)");

new Thread(
() -> {
try (Connection conn = setConnection("&socketTimeout=1000")) {
Statement stmt2 = conn.createStatement();
stmt2.execute("BEGIN");
stmt2.execute("DELETE FROM ensureSocketTimeoutState WHERE id IN (1, 3, 5, 7, 9)");
stmt2.execute("SELECT SLEEP(30)");
} catch (SQLException e) {
// eat
}
})
.start();
Thread.sleep(100);

long insertStart = System.currentTimeMillis();

try (Connection conn = setConnection()) {
Statement stmt2 = conn.createStatement();
stmt2.execute("BEGIN");
stmt2.execute("INSERT INTO ensureSocketTimeoutState VALUES (2)");
stmt2.execute("COMMIT");
}
assertTrue(System.currentTimeMillis() - insertStart < 5000);
}

@Test
public void prepareStatementCols() throws SQLException {
try (PreparedStatement preparedStatement =
Expand Down

0 comments on commit 0f04e45

Please sign in to comment.