使用websocket连接方式写入数据的时报错,无法创建连接

【TDengine 使用环境】
测试环境

【TDengine 版本】
3.3.7.0

【操作系统以及版本】
centos7

【部署方式】容器/非容器部署
容器

【集群节点数】
1

【集群副本数】
1

【描述业务影响】
按照教程中的【高效写入】部分,测试websocket连接的写入性能

【问题复现路径/shan】做过哪些操作出现的问题
使用websocket连接方式

【遇到的问题:问题现象及影响】
测试数据量:大概30个线程以500ms/条的频率写入数据。

使用websocket连接方式的场合:测试程序运行不久就会报连接失败的错误,之后即使停止测试程序,数据库也无法再次连接(停止测试程序很长时间后),必须重启才能恢复使用。

使用rest连接方式的场合:测试程序可以长时间运行,资源占用率也很低,大概cpu:50%, mem:800MB左右.

测试代码如下:

package avicit.tsd.test;

import cn.hutool.core.date.DateUtil;
import com.taosdata.jdbc.TSDBDriver;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.Properties;

public class WsTest {

    public static void main(String[] args) throws Exception {
        Properties properties = new Properties();
        properties.setProperty(TSDBDriver.PROPERTY_KEY_ASYNC_WRITE, "stmt");
        properties.setProperty(TSDBDriver.PROPERTY_KEY_BATCH_SIZE_BY_ROW, "10000");
        properties.setProperty(TSDBDriver.PROPERTY_KEY_CACHE_SIZE_BY_ROW, "100000");
        properties.setProperty(TSDBDriver.PROPERTY_KEY_BACKEND_WRITE_THREAD_NUM, "5");
        properties.setProperty(TSDBDriver.PROPERTY_KEY_ENABLE_AUTO_RECONNECT, "true");
        properties.setProperty(TSDBDriver.PROPERTY_KEY_MESSAGE_WAIT_TIMEOUT, "5000");
        properties.setProperty(TSDBDriver.PROPERTY_KEY_COPY_DATA, "false");
        properties.setProperty(TSDBDriver.PROPERTY_KEY_STRICT_CHECK, "false");
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl("jdbc:TAOS-WS://10.216.36.62:6041/iot_platform?characterEncoding=UTF-8&useUnicode=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&useInformationSchema=true");
        config.setUsername("root");
        config.setPassword("taosdata");
        config.setMinimumIdle(10);
        config.setMaximumPoolSize(20);
        config.setConnectionTimeout(30000);
        config.setMaxLifetime(0);
        config.setIdleTimeout(0);
        config.setConnectionTestQuery("SELECT 1");
        config.setDataSourceProperties(properties);
        HikariDataSource dataSource = new HikariDataSource(config);

        for (int i = 0 ; i < 30 ; i++) {
            new Thread(() -> {
                write(dataSource);
            }).start();
        }

    }

    private static void write(DataSource dataSource) {
        for (;;) {
            try (Connection connection = dataSource.getConnection()) {
                String sql = "INSERT INTO iot_platform.? using iot_platform.equipment TAGS ('test') VALUES (now(),?,?,?)";
                try (PreparedStatement pstmt = connection.prepareStatement(sql)) {
                    for (int i = 0; i < 100; i++) {
                        pstmt.setString(1, "test_" + i);
                        pstmt.setString(2, "test_" + i);
                        pstmt.setString(3, String.valueOf(i));
                        pstmt.setString(4, DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS"));
                        pstmt.addBatch();
                    }
                    pstmt.executeBatch();
                    Thread.sleep(500);
                }
            } catch (Exception e) {
                System.out.printf("Failed to insert to table meters using efficient writing, %sErrMessage: %s%n",
                        e instanceof SQLException ? "ErrCode: " + ((SQLException) e).getErrorCode() + ", " : "",
                        e.getMessage());
                e.printStackTrace();
            }
        }
    }
}

【资源配置】
服务器配置:8c16g

【报错完整截图】
测试程序报错信息

数据库报错信息

是否用了多副本?需要查看taosdlog日志中的ERROR信息进一步判断

单节点部署,没启用多副本,taosd日志如下:
09/03 17:49:47.217019 00000404 C RPC WARN http-report failed to acquire recv buf since Ref is not there
09/03 17:49:47.218022 00000404 C RPC WARN http-report failed to acquire recv buf since Ref is not there
09/03 17:49:53.113935 00000102 C UTL INFO report client cont with QID:0x1000000062d6100
09/03 17:50:17.234499 00000404 C RPC WARN http-report failed to acquire recv buf since Ref is not there
09/03 17:50:17.235806 00000404 C RPC WARN http-report failed to acquire recv buf since Ref is not there
09/03 17:50:23.113917 00000102 C UTL INFO report client cont with QID:0x1000000062d9500
09/03 17:50:47.251655 00000404 C RPC WARN http-report failed to acquire recv buf since Ref is not there
09/03 17:50:47.251697 00000404 C RPC WARN http-report failed to acquire recv buf since Ref is not there
09/03 17:50:53.114061 00000102 C UTL INFO report client cont with QID:0x1000000062dc900
09/03 17:51:17.265378 00000404 C RPC WARN http-report failed to acquire recv buf since Ref is not there
09/03 17:51:17.266066 00000404 C RPC WARN http-report failed to acquire recv buf since Ref is not there
09/03 17:51:23.113878 00000102 C UTL INFO report client cont with QID:0x1000000062dfd00
09/03 17:51:23.115251 00000404 C RPC WARN http-report failed to acquire recv buf since Ref is not there

我现在的遇到问题就是,使用ws连接器的时候,只要调用PreparedStatement.executeBatch()或者方法PreparedStatement.execute()一次,数据库就会变得无法使用,拒绝连接,只有重启才能继续使用。使用Statement就可以正常插入数据。假如是我的代码写的有问题,但是只调用一次PreparedStatement.execute()方法也不应该使得数据库无法使用呀。

tdentine版本:3.3.7.0

jdbc版本:taos-jdbcdriver:3.7.2(taos-jdbcdriver:3.7.0也一样)

错误日志如下:

09/03 18:18:32.486224 00000321 DB ERROR QID:0x4000000000000063 latency:3.684571093s, sql:insert into km_iot_tsdb_6043 using keeper_monitor tags (‘iot-tsdb:6043’) values ( now, 0.016667, 0.100702, 0), err:Post “http://127.0.0.1:6041/rest/sql/log?req_id=4697554515144998993”: read tcp 127.0.0.1:36528->127.0.0.1:6041: read: connection reset by peer
09/03 18:18:32.486272 00000321 MON ERROR execute sql:insert into km_iot_tsdb_6043 using keeper_monitor tags (‘iot-tsdb:6043’) values ( now, 0.016667, 0.100702, 0), error:Post “http://127.0.0.1:6041/rest/sql/log?req_id=4697554515144998993”: read tcp 127.0.0.1:36528->127.0.0.1:6041: read: connection reset by peer
/usr/bin/entrypoint.sh: line 116: 280 Segmentation fault (core dumped) taosadapter
09/03 18:18:43.804073 00000321 DB ERROR QID:0x4000000000000065 latency:716.324µs, sql:insert into km_iot_tsdb_6043 using keeper_monitor tags (‘iot-tsdb:6043’) values ( now, 0.008333, 0.100702, 0), err:Post “http://127.0.0.1:6041/rest/sql/log?req_id=4697554515205816402”: dial tcp 127.0.0.1:6041: connect: connection refused
09/03 18:18:43.804105 00000321 MON ERROR execute sql:insert into km_iot_tsdb_6043 using keeper_monitor tags (‘iot-tsdb:6043’) values ( now, 0.008333, 0.100702, 0), error:Post “http://127.0.0.1:6041/rest/sql/log?req_id=4697554515205816402”: dial tcp 127.0.0.1:6041: connect: connection refused
09/03 18:18:53.786668 00000321 DB ERROR QID:0x10000000000ea00 latency:429.519µs, sql:insert into log.taosd_cluster_basic_5088643727513000061 using taosd_cluster_basic tags (‘5088643727513000061’) values (1756894733785, ‘localhost:6030’, 1, ‘3.3.7.0’) , err:Post “http://127.0.0.1:6041/rest/sql/log?req_id=4697554515246710867”: dial tcp 127.0.0.1:6041: connect: connection refused
09/03 18:18:53.786698 00000321 GEN ERROR QID:0x10000000000ea00 insert taosd_cluster_basic error, msg:Post “http://127.0.0.1:6041/rest/sql/log?req_id=4697554515246710867”: dial tcp 127.0.0.1:6041: connect: connection refused
09/03 18:18:53.787469 00000321 WEB ERROR
2025/09/03 18:18:53 [Recovery] 2025/09/03 - 18:18:53 panic recovered:
runtime error: invalid memory address or nil pointer dereference
/root/.gvm/gos/go1.24.2/src/runtime/panic.go:262 (0x47daf8)
/root/.gvm/gos/go1.24.2/src/runtime/signal_unix.go:925 (0x47dac8)
/data/release/main/TDinternal/community/tools/keeper/api/gen_metric.go:303 (0xb8976e)
/data/release/main/TDinternal/community/tools/keeper/api/gen_metric.go:262 (0xb88c1c)
/data/release/main/TDinternal/community/tools/keeper/api/gen_metric.go:217 (0xb88244)
/root/.gvm/pkgsets/go1.24.2/global/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174 (0x95566e)
/root/.gvm/pkgsets/go1.24.2/global/pkg/mod/github.com/gin-gonic/gin@v1.9.1/recovery.go:102 (0x95565b)
/data/release/main/TDinternal/community/tools/keeper/infrastructure/log/web.go:53 (0xa9817b)
/root/.gvm/pkgsets/go1.24.2/global/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174 (0xa97b86)
/data/release/main/TDinternal/community/tools/keeper/infrastructure/log/web.go:24 (0xa97b6d)
/root/.gvm/pkgsets/go1.24.2/global/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174 (0x9544ad)
/root/.gvm/pkgsets/go1.24.2/global/pkg/mod/github.com/gin-gonic/gin@v1.9.1/gin.go:620 (0x954144)
/root/.gvm/pkgsets/go1.24.2/global/pkg/mod/github.com/gin-gonic/gin@v1.9.1/gin.go:576 (0x953c89)
/root/.gvm/gos/go1.24.2/src/net/http/server.go:3301 (0x71c44d)
/root/.gvm/gos/go1.24.2/src/net/http/server.go:2102 (0x6f9e84)
/root/.gvm/gos/go1.24.2/src/runtime/asm_amd64.s:1700 (0x483880)

需具体排查,如遇相同问题,请重新发帖。

此话题已在最后回复的 30 天后被自动关闭。不再允许新回复。