You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
iferr!=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)
iferr!=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
The text was updated successfully, but these errors were encountered:
When ResetSession was added, it was called when the connection is put into the pool.
Thet is why we only flag on ResetSession and checkConnLiveness on sending query.
Issue description
Now the MySQL connection implements database/sql driver's
ResetSession
ofSessionResetter
interface by setmc.reset
to be true and callconnCheck
in connection'swritePacket
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
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
The text was updated successfully, but these errors were encountered: