2
0

stdlib: Use Ping instead of CheckConn in ResetSession

CheckConn is deprecated. It doesn't detect all network outages. It
causes a 1ms delay while it tries to read the connection. Ping incurs a
round trip but that means it is a much stronger guarantee that the
connection is usable. In addition, if the application and the database
are on the same network it will actually be faster as round trip times
are typically a few hundred microseconds.
This commit is contained in:
Jack Christensen
2023-10-26 20:41:44 -05:00
parent 7a4bb7edb5
commit cf6ef75f91
+1 -1
View File
@@ -548,7 +548,7 @@ func (c *Conn) ResetSession(ctx context.Context) error {
now := time.Now()
if now.Sub(c.lastResetSessionTime) > time.Second {
if err := c.conn.PgConn().CheckConn(); err != nil {
if err := c.conn.PgConn().Ping(ctx); err != nil {
return driver.ErrBadConn
}
}