Go database connection pool timeout An established connection was aborted by the software in your host machine

After a new computer recently, I found this error message from time to time in the previous Go project in the local development environment: 127.0.0.1:3306: wsarecv: An established connection was aborted by the software in your host machine.

Check that it is the problem caused by the golang sql connection pool timeout and the automatic disconnection of the database.
If it is a mysql database, the database itself has a timeout period, after which the database will automatically disconnect.

Approach:

1. View the database disconnection time

show global variables like "%timeout%"

Mainly look at the value of interactive_timeout and wait_timeout. (interactive_timeout is for interactive connections, and wait_timeout is for non-interactive connections. The so-called interactive connection, that is, the CLIENT_INTERACTIVE option is used in the mysql_real_connect() function. To put it bluntly, connecting to the database through the mysql client is an interactive connection. The jdbc connection to the database is a non-interactive connection. When the connection is started, according to the type of connection, confirm whether the value of the session variable wait_timeout is inherited from the global variable wait_timeout or interactive_timeout)

The default value of mysql's interactive_timeout is 120, and the default value of wait_timeout is 120.

SetMaxOpenConns is used to set the maximum number of open connections. The default value is 0, which means no limit.
SetMaxIdleConns is used to set the number of idle connections.
SetConnMaxLifetime(time.Duration(120) * time.Second) //Set the timeout time to be consistent with the timeout time of mysql (if not set, it will be permanently valid by default)

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324038605&siteId=291194637