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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user