TiDB Connection Error

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: tidb 连接报错

| username: 等一分钟

[TiDB Usage Environment] Production Environment
[TiDB Version] 6.5.1
[Encountered Problem: Problem Phenomenon and Impact]
SQLException Exception: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure. The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

[Resource Configuration]
Program Database Connection Configuration

| username: 等一分钟 | Original post link

tidb:
datasource:
druid: url: jdbc:mysql://xxxx:4000/xxx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&serverTimezone=Asia/Shanghai
driver-class-name: com.mysql.jdbc.Driver
username: xxx
initialSize: 10
minIdle: 10
maxActive: 100
maxWait: 600000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000

| username: 等一分钟 | Original post link

The value of the wait_timeout variable is 28800, and the TiDB cluster is normal. Could it be that after the connection is interrupted due to timeout, the program reports an error when it is used again?

| username: Running | Original post link

If you use a connection pool, remove the waittimeout and connecttimeout at the database layer. Additionally, you can set the keep-alive time for the connection pool.

| username: 等一分钟 | Original post link

How do I remove waittimeout and connecttimeout?

| username: caiyfc | Original post link

The image is not visible. Please provide the text you need translated.

| username: 等一分钟 | Original post link

The wait_timeout for TiDB is 28800 seconds. Sleep connections that exceed this timeout will be killed by TiDB, right?

| username: 考试没答案 | Original post link

Is this a system you are already using or a newly launched one?

| username: 考试没答案 | Original post link

There are generally three situations for this issue that I have encountered:

  1. Driver issues, which typically occur with newly launched systems. For long-running systems, it’s not a driver issue.
  2. Database disconnection. This can be resolved by setting up a reconnection mechanism.
  3. Too many connections. You can increase TiDB’s connection recycling time. Because there are too many connections, new connections cannot be established.

Please refer to this.

| username: 等一分钟 | Original post link

There are many systems already.

| username: TiDBer_pkQ5q1l0 | Original post link

It is also possible that the application’s connection pool is full.

| username: 等一分钟 | Original post link

The connection pool has a maximum of 100 connections, which should not be an issue for AP-type applications.

| username: 等一分钟 | Original post link

If the connection pool is full, there should be keywords like “pool” or similar.

| username: 等一分钟 | Original post link

The image is not visible. Please provide the text you need translated.

| username: 等一分钟 | Original post link

Is the sleep time so long because wait_timeout is not working?

| username: Running | Original post link

This is for connection pool initialization, it needs to stay alive.

| username: yulei7633 | Original post link

It should be that the connection pool is full.