-
Couldn't load subscription status.
- Fork 2.3k
Description
Issue description
Now the MySQL connection implements database/sql driver's ResetSession of SessionResetter interface by set mc.reset to be true and call connCheck in connection's writePacket method in #934.
I'm wondering whether we can put connection liveness checking logic at ResetSession method directly?
From user point of view, they may want to get one sticky connection to set session variable then do query by using db.Conn.
In such scenario, it's possible to get bad connection if user doesn't configure connection lifetime and the connection get from the pool exceed the server side's wait_timeout. If we can put connCheck at ResetSession method, I think the issue can be resolved.
Example code
conn, err := db.Conn(ctx)
if err != nil {
// err can't be driver.ErrBadConn because db.Conn method will fallback to create new connection after retry.
}
rows, err := conn.QueryContext(ctx, query, args)
if err != nil {
// err can be driver.ErrBadConn if connection lifetime exceed server side wait_timeout.
}Error log
N/A
Configuration
Driver version (or git SHA): master branch
Go version: go 1.20.1
Server version: MySQL 5.7
Server OS: MacOS