database/sql: DB.Conn always returns a cached connection #29684
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When using
sql.DB.Conn()
a badsql.ErrBadConn
error was returned because the connections were terminated by the server (usingpg_terminate_backend
on postgres).This by it self is not a bad thing but seems to not confirm with
sql.DB.ExecContext()
andsql.DB.PingContext()
which actually kept working by opening a new connection.While looking at the code I noticed that sq.DB.ExecContext() did
cachedOrNewConn
and thenalwaysNewConn
to ensure a new connection was available.The code in
sql.DB.Conn()
seems to be doing acachedOrNewConn
and thencachedOrNewConn
causing a cached/bad connection to be returned.Probably this can be fixed by replacing src/database/sql/sql.go line 1701:
What did you expect to see?
I expected
sql.DB.Conn()
to use the cached connections and otherwise create a new one similar to the rest of the library.What did you see instead?
sql.DB.Conn()
returned a cached/bad connection and did not try to create a new one.The text was updated successfully, but these errors were encountered: