Add a timeout to pgxpool min connection creation

Ensure that CreateResource can't hang.
pull/678/head
Jack Christensen 2020-02-05 11:25:15 -06:00
parent cb1a1ebefa
commit 22ad987698
1 changed files with 5 additions and 1 deletions

View File

@ -323,7 +323,11 @@ func (p *Pool) checkIdleConnsHealth() {
func (p *Pool) checkMinConns() {
for i := p.minConns - p.Stat().TotalConns(); i > 0; i-- {
go p.p.CreateResource(context.Background())
go func() {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
p.p.CreateResource(ctx)
}()
}
}