Skip to content

Commit 7684a5c

Browse files
authored
fix: deadlock when binding a wrong type in efficient writing (#252)
1 parent 3f1fdad commit 7684a5c

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/main/java/com/taosdata/jdbc/ws/WSEWPreparedStatement.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,9 @@ private void writeBlockWithRetry() throws SQLException {
418418
toBeBindTagCount,
419419
toBeBindColCount,
420420
precision);
421-
} catch (SQLException e) {
421+
} catch (Exception e) {
422422
lastError = e;
423-
log.error("Error in serialize data to block, stmt id: {}, req id: {}" +
424-
"code: {}, msg: {}",
425-
stmtId, reqId,
426-
e.getErrorCode(), e.getMessage());
423+
log.error("Error in serialize data to block, stmt id: {}, req id: {}", stmtId, reqId, e);
427424
break;
428425
}
429426

src/test/java/com/taosdata/jdbc/ws/stmt/WsEfficientWritingTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class WsEfficientWritingTest {
1717
private final String tableName = "wpt";
1818
private final String tableNameCopyData = "wpt_cp";
1919
private final String tableReconnect = "wpt_rc";
20+
private final String tableNcharTag = "wpt_nchar";
2021
private final String asyncSqlTable = tableReconnect;
2122
private Connection connection;
2223
private TaosAdapterMock taosAdapterMock;
@@ -70,7 +71,7 @@ public void testStmt2InsertStdApiNoTag() throws SQLException {
7071
}
7172

7273
Assert.assertEquals(numOfSubTable * numOfRow, Utils.getSqlRows(connection, db_name + "." + tableName));
73-
}
74+
}
7475

7576
@Test
7677
public void testCopyData() throws SQLException {
@@ -347,6 +348,24 @@ public void testColumnDataCloseBatchThrowsSQLException() throws SQLException {
347348
}
348349
}
349350

351+
@Test(expected = SQLException.class)
352+
public void testNcharTagThrowsSQLException() throws SQLException {
353+
String sql = "INSERT INTO " + db_name + "." + tableNcharTag + "(tbname, ts, i, tag_nchar) VALUES (?,?,?,?)";
354+
try (Connection con = getConnection(false);
355+
PreparedStatement pstmt = con.prepareStatement(sql)) {
356+
long current = System.currentTimeMillis();
357+
for (int i = 0; i < 1000; i++) {
358+
pstmt.setString(1, "ncahr_bind_1");
359+
pstmt.setTimestamp(2, new Timestamp(current + i));
360+
pstmt.setInt(3, 100);
361+
pstmt.setString(4, "中国人");
362+
pstmt.addBatch();
363+
pstmt.executeBatch();
364+
}
365+
pstmt.executeUpdate();
366+
}
367+
}
368+
350369
@Before
351370
public void before() throws SQLException {
352371
connection = getConnection(false);
@@ -357,6 +376,8 @@ public void before() throws SQLException {
357376
statement.execute("create stable if not exists " + db_name + "." + tableName + " (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId INT, location BINARY(24))");
358377
statement.execute("create stable if not exists " + db_name + "." + tableNameCopyData + " (ts TIMESTAMP, b varbinary(10)) TAGS (groupId INT)");
359378
statement.execute("create stable if not exists " + db_name + "." + tableReconnect + " (ts TIMESTAMP, i INT) TAGS (groupId INT)");
379+
statement.execute("create stable if not exists " + db_name + "." + tableNcharTag + " (ts TIMESTAMP, i INT) TAGS (tag_nchar nchar(100))");
380+
360381
statement.close();
361382

362383
createSubTable();

0 commit comments

Comments
 (0)