From 82bac8221328ff97952942cbee4b6ea52f76cb60 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Thu, 3 Dec 2020 19:41:03 -0600 Subject: [PATCH] stdlib: consider any Ping failure as fatal refs #672 --- stdlib/sql.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/stdlib/sql.go b/stdlib/sql.go index a1e966eb..10c104da 100644 --- a/stdlib/sql.go +++ b/stdlib/sql.go @@ -370,7 +370,15 @@ func (c *Conn) Ping(ctx context.Context) error { return driver.ErrBadConn } - return c.conn.Ping(ctx) + err := c.conn.Ping(ctx) + if err != nil { + // A Ping failure implies some sort of fatal state. The connection is almost certainly already closed by the + // failure, but manually close it just to be sure. + c.Close() + return driver.ErrBadConn + } + + return nil } func (c *Conn) CheckNamedValue(*driver.NamedValue) error {