From cf6ef75f916648857cf7b46322d6d7af7d372917 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Thu, 26 Oct 2023 20:41:44 -0500 Subject: [PATCH] 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. --- stdlib/sql.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/sql.go b/stdlib/sql.go index f688f70c6..c5be1a3f2 100644 --- a/stdlib/sql.go +++ b/stdlib/sql.go @@ -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 } }