File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package pgxpool
22
33import (
44 "context"
5+ "errors"
56 "math/rand"
67 "runtime"
78 "strconv"
@@ -565,7 +566,10 @@ func (p *Pool) Acquire(ctx context.Context) (c *Conn, err error) {
565566 }()
566567 }
567568
568- for {
569+ // Try to acquire from the connection pool up to maxConns + 1 times, so that
570+ // any that fatal errors would empty the pool and still at least try 1 fresh
571+ // connection.
572+ for range p .maxConns + 1 {
569573 res , err := p .p .Acquire (ctx )
570574 if err != nil {
571575 return nil , err
@@ -599,6 +603,7 @@ func (p *Pool) Acquire(ctx context.Context) (c *Conn, err error) {
599603
600604 return cr .getConn (p , res ), nil
601605 }
606+ return nil , errors .New ("pgxpool: detected infinite loop acquiring connection; likely bug in PrepareConn or BeforeAcquire hook" )
602607}
603608
604609// AcquireFunc acquires a *Conn and calls f with that *Conn. ctx will only affect the Acquire. It has no effect on the
You can’t perform that action at this time.
0 commit comments