Skip to content

Commit c9792c0

Browse files
authored
fix: WebSocket statement timeout setting resets transport's timeout (#290)
* fix: WebSocket statement timeout setting resets transport's timeout Closes TD-38565 * --amend
1 parent b6841d7 commit c9792c0

16 files changed

+159
-86
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
target
33
.vscode
44
.DS_Store
5+
cleanup_branches.sh
56
*.iml
67
htmlReport/
78
src/test/java/com/taosdata/jdbc/manual/

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [unreleased]
9+
10+
**Full Changelog**: [3.7.6...](https://github.com/taosdata/taos-connector-jdbc/compare/3.7.6...)
11+
12+
### Bug Fixes
13+
14+
15+
- Load properties issue in windows (#289) ([b6841d7](https://github.com/taosdata/taos-connector-jdbc/commit/b6841d726f9520556ddf069a5e0aea95af3be876))
16+
17+
818
## [3.7.6] - 2025-10-17
919

1020
**Full Changelog**: [3.7.5...3.7.6](https://github.com/taosdata/taos-connector-jdbc/compare/3.7.5...3.7.6)

deploy-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.taosdata.jdbc</groupId>
77
<artifactId>taos-jdbcdriver</artifactId>
8-
<version>3.7.6</version>
8+
<version>3.7.7</version>
99

1010
<packaging>jar</packaging>
1111

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.taosdata.jdbc</groupId>
55
<artifactId>taos-jdbcdriver</artifactId>
6-
<version>3.7.6</version>
6+
<version>3.7.7</version>
77

88
<packaging>jar</packaging>
99
<name>JDBCDriver</name>

src/main/java/com/taosdata/jdbc/AbstractDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected Connection getWSConnection(String url, ConnectionParam param, Properti
112112
transport.checkConnection(param.getConnectTimeout());
113113

114114
ConnectReq connectReq = new ConnectReq(param);
115-
ConnectResp auth = (ConnectResp) transport.send(new Request(Action.CONN.getAction(), connectReq));
115+
ConnectResp auth = (ConnectResp) transport.send(new Request(Action.CONN.getAction(), connectReq), param.getRequestTimeout());
116116

117117
if (Code.SUCCESS.getCode() != auth.getCode()) {
118118
transport.close();

src/main/java/com/taosdata/jdbc/TSDBConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public abstract class TSDBConstants {
9090
public static final int DOUBLE_SCALE = 31;
9191

9292
public static final String DEFAULT_PRECISION = "ms";
93-
93+
public static final int DEFAULT_MESSAGE_WAIT_TIMEOUT = 60_000;
9494
public static final boolean DEFAULT_BATCH_ERROR_IGNORE = false;
9595

9696

src/main/java/com/taosdata/jdbc/rs/ConnectionParam.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.taosdata.jdbc.rs;
22

3+
import com.taosdata.jdbc.TSDBConstants;
34
import com.taosdata.jdbc.TSDBDriver;
45
import com.taosdata.jdbc.TSDBError;
56
import com.taosdata.jdbc.TSDBErrorNumbers;
67
import com.taosdata.jdbc.common.Endpoint;
78
import com.taosdata.jdbc.utils.HttpClientPoolUtil;
89
import com.taosdata.jdbc.utils.StringUtils;
910
import com.taosdata.jdbc.utils.Utils;
10-
import com.taosdata.jdbc.ws.Transport;
1111
import io.netty.buffer.ByteBuf;
1212

1313
import java.io.UnsupportedEncodingException;
@@ -411,7 +411,7 @@ public static ConnectionParam getParam(Properties properties) throws SQLExceptio
411411
properties.getProperty(TSDBDriver.HTTP_CONNECT_TIMEOUT, HttpClientPoolUtil.DEFAULT_CONNECT_TIMEOUT));
412412

413413
int requestTimeout = Integer.parseInt(properties.getProperty(TSDBDriver.PROPERTY_KEY_MESSAGE_WAIT_TIMEOUT,
414-
String.valueOf(Transport.DEFAULT_MESSAGE_WAIT_TIMEOUT)));
414+
String.valueOf(TSDBConstants.DEFAULT_MESSAGE_WAIT_TIMEOUT)));
415415

416416
int connectMode = Integer.parseInt(properties.getProperty(TSDBDriver.PROPERTY_KEY_CONNECT_MODE,"0"));
417417
if (connectMode < 0 || connectMode > 1){

src/main/java/com/taosdata/jdbc/utils/StmtUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static Stmt2PrepareResp initStmtWithRetry(Transport transport, String sql
3030
}
3131
stmtId = resp.getStmtId();
3232
Request prepare = RequestFactory.generatePrepare(stmtId, reqId, sql);
33-
Stmt2PrepareResp prepareResp = (Stmt2PrepareResp) transport.send(prepare, false);
33+
Stmt2PrepareResp prepareResp = (Stmt2PrepareResp) transport.send(prepare, false, transport.getConnectionParam().getRequestTimeout());
3434

3535
if (Code.SUCCESS.getCode() != prepareResp.getCode()) {
3636
Request close = RequestFactory.generateClose(stmtId, reqId);

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
public class AbsWSPreparedStatement extends WSRetryableStmt implements TaosPrepareStatement {
3737
private static final List<Object> nullTag = Collections.singletonList(null);
38-
protected int queryTimeout = 0;
3938
protected final Map<Integer, Column> colOrderedMap = new HashMap<>();
4039
private final PriorityQueue<ColumnInfo> tag = new PriorityQueue<>();
4140
private final PriorityQueue<ColumnInfo> colListQueue = new PriorityQueue<>();
@@ -61,23 +60,6 @@ public AbsWSPreparedStatement(Transport transport,
6160
super(connection, param, database, transport, instanceId, new StmtInfo(prepareResp, sql), new AtomicInteger());
6261
this.tableInfo = TableInfo.getEmptyTableInfo();
6362
}
64-
65-
@Override
66-
public int getQueryTimeout() throws SQLException {
67-
return queryTimeout;
68-
}
69-
70-
@Override
71-
public void setQueryTimeout(int seconds) throws SQLException {
72-
if (isClosed())
73-
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
74-
if (seconds < 0)
75-
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
76-
77-
this.queryTimeout = seconds;
78-
transport.setTimeout(seconds * 1000L);
79-
}
80-
8163
@Override
8264
public boolean execute() throws SQLException {
8365
if (isClosed())
@@ -753,7 +735,7 @@ public void close() throws SQLException {
753735
if (transport.isConnected() && stmtInfo.getStmtId() != 0) {
754736
long reqId = ReqId.getReqID();
755737
Request close = RequestFactory.generateClose(stmtInfo.getStmtId(), reqId);
756-
transport.send(close);
738+
transport.send(close, this.getQueryTimeoutInMs());
757739
}
758740
super.close();
759741
}

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.taosdata.jdbc.ws;
22

3+
import com.taosdata.jdbc.TSDBConstants;
34
import com.taosdata.jdbc.TSDBError;
45
import com.taosdata.jdbc.TSDBErrorNumbers;
56
import com.taosdata.jdbc.enums.WSFunction;
@@ -27,17 +28,13 @@
2728
public class Transport implements AutoCloseable {
2829
private static final Logger log = LoggerFactory.getLogger(Transport.class);
2930
private static final boolean isTest = "test".equalsIgnoreCase(System.getProperty("ENV_TAOS_JDBC_TEST"));
30-
31-
public static final int DEFAULT_MESSAGE_WAIT_TIMEOUT = 60_000;
32-
3331
public static final int TSDB_CODE_RPC_NETWORK_UNAVAIL = 0x0B;
3432
public static final int TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED = 0x20;
35-
3633
private final AtomicInteger reconnectCount = new AtomicInteger(0);
3734

3835
private final ArrayList<WSClient> clientArr = new ArrayList<>();
3936
private final InFlightRequest inFlightRequest;
40-
private long timeout;
37+
private final long defaultTimeout;
4138
private volatile boolean closed = false;
4239

4340
private final ConnectionParam connectionParam;
@@ -50,10 +47,13 @@ protected Transport() {
5047
this.inFlightRequest = null;
5148
this.connectionParam = null;
5249
this.wsFunction = null;
50+
this.defaultTimeout = TSDBConstants.DEFAULT_MESSAGE_WAIT_TIMEOUT;
5351
}
5452
public Transport(WSFunction function,
5553
ConnectionParam param,
5654
InFlightRequest inFlightRequest) throws SQLException {
55+
this.defaultTimeout = param.getRequestTimeout();
56+
5757
// master slave mode
5858
WSClient slave = WSClient.getSlaveInstance(param, function, this);
5959
if (slave != null){
@@ -75,18 +75,7 @@ public Transport(WSFunction function,
7575
this.inFlightRequest = inFlightRequest;
7676
this.connectionParam = param;
7777
this.wsFunction = function;
78-
79-
setTimeout(param.getRequestTimeout());
8078
}
81-
public void setTimeout(long timeout) {
82-
if (timeout < 0){
83-
timeout = DEFAULT_MESSAGE_WAIT_TIMEOUT;
84-
} else if (timeout == 0){
85-
timeout = Integer.MAX_VALUE;
86-
}
87-
this.timeout = timeout;
88-
}
89-
9079
private void reconnect(boolean isTmq) throws SQLException {
9180
synchronized (this) {
9281
if (isConnected()){
@@ -118,10 +107,14 @@ private void tmqRethrowConnectionCloseException() throws SQLException {
118107
}
119108
}
120109
@SuppressWarnings("all")
110+
121111
public Response send(Request request) throws SQLException {
122-
return send(request, true);
112+
return send(request, true, defaultTimeout);
113+
}
114+
public Response send(Request request, long timeout) throws SQLException {
115+
return send(request, true, timeout);
123116
}
124-
public Response send(Request request, boolean reSend) throws SQLException {
117+
public Response send(Request request, boolean reSend, long timeout) throws SQLException {
125118
if (isClosed()){
126119
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED, "Websocket Not Connected Exception");
127120
}
@@ -164,11 +157,11 @@ public Response send(Request request, boolean reSend) throws SQLException {
164157
}
165158
return response;
166159
}
167-
public Response send(String action, long reqId, long resultId, long type, byte[] rawData) throws SQLException {
168-
return send(action, reqId, resultId, type, rawData, EMPTY_BYTE_ARRAY);
160+
public Response send(String action, long reqId, long resultId, long type, byte[] rawData, long timeout) throws SQLException {
161+
return send(action, reqId, resultId, type, rawData, EMPTY_BYTE_ARRAY, timeout);
169162
}
170163

171-
public Response send(String action, long reqId, long resultId, long type, byte[] rawData, byte[] rawData2) throws SQLException {
164+
public Response send(String action, long reqId, long resultId, long type, byte[] rawData, byte[] rawData2, long timeout) throws SQLException {
172165
if (isClosed()){
173166
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED, "Websocket Not Connected Exception");
174167
}
@@ -246,7 +239,7 @@ public void sendFetchBlockAsync(long reqId,
246239
}
247240
}
248241

249-
public Response send(String action, long reqId, ByteBuf buffer, boolean resend) throws SQLException {
242+
public Response send(String action, long reqId, ByteBuf buffer, boolean resend, long timeout) throws SQLException {
250243
if (isClosed()){
251244
Utils.releaseByteBuf(buffer);
252245
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED, "Websocket Not Connected Exception");
@@ -304,7 +297,7 @@ private void handleErrInMasterSlaveMode(Response response) throws InterruptedExc
304297
}
305298
}
306299

307-
public Response sendWithoutRetry(Request request) throws SQLException {
300+
public Response sendWithoutRetry(Request request, long timeout) throws SQLException {
308301
if (isClosed()){
309302
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED, "Websocket Not Connected Exception");
310303
}
@@ -414,7 +407,7 @@ public void shutdown() {
414407
if (inFlightRequest.hasInFlightRequest()) {
415408
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
416409
try {
417-
TimeUnit.MILLISECONDS.sleep(timeout);
410+
TimeUnit.MILLISECONDS.sleep(defaultTimeout);
418411
} catch (InterruptedException e) {
419412
// ignore
420413
}
@@ -440,7 +433,7 @@ private boolean reconnectCurNode(boolean isTmq) throws SQLException {
440433
// send con msgs
441434
ConnectReq connectReq = new ConnectReq(connectionParam);
442435
ConnectResp auth;
443-
auth = (ConnectResp) sendWithoutRetry(new Request(Action.CONN.getAction(), connectReq));
436+
auth = (ConnectResp) sendWithoutRetry(new Request(Action.CONN.getAction(), connectReq), defaultTimeout);
444437

445438
if (Code.SUCCESS.getCode() == auth.getCode()) {
446439
return true;

0 commit comments

Comments
 (0)