2
0

Check conn liveness before using when idle for more than 1 second

Implemented in pgxpool.Pool and database/sql.

https://github.com/jackc/pgx/issues/672
This commit is contained in:
Jack Christensen
2022-06-25 17:58:53 -05:00
parent 26eda0f86d
commit 03da9fcec6
4 changed files with 139 additions and 5 deletions
+9
View File
@@ -417,6 +417,15 @@ func (p *Pool) Acquire(ctx context.Context) (*Conn, error) {
}
cr := res.Value()
if res.IdleDuration() > time.Second {
err := cr.conn.PgConn().CheckConn()
if err != nil {
res.Destroy()
continue
}
}
if p.beforeAcquire == nil || p.beforeAcquire(ctx, cr.conn) {
return cr.getConn(p, res), nil
}