pgx
pgx copied to clipboard
Do not close the connection when the error does not indicate that the connection is broken.
Is your feature request related to a problem? Please describe.
Let's say the following code in the package stdlib
func (c *Conn) Ping(ctx context.Context) error {
if c.conn.IsClosed() {
return driver.ErrBadConn
}
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
}
The connection will be closed in case of an error returned by c.conn.Ping, however not all errors are meant to be the connection is in a fatal state. For instance, the error conn busy is caused by using the same connection concurrently, but the connection is workable when the locker is released
Describe the solution you'd like
Check the error type to determine the close operation is necessary
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
Additional context Add any other context or screenshots about the feature request here.
Are there any recoverable errors beside conn busy? I'd consider conn busy to be a bug in the application code.