Skip to content

Commit ab52391

Browse files
jackcclaude
andcommitted
Use single Stat snapshot in checkMinConns
Two separate Stat() calls could return inconsistent values for TotalConns and IdleConns. Capture once for a consistent snapshot. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ee304a8 commit ab52391

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

pgxpool/pool.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,8 @@ func (p *Pool) checkMinConns() error {
558558
// off this check
559559

560560
// Create the number of connections needed to get to both minConns and minIdleConns
561-
toCreate := max(p.minConns-p.Stat().TotalConns(), p.minIdleConns-p.Stat().IdleConns())
561+
stat := p.Stat()
562+
toCreate := max(p.minConns-stat.TotalConns(), p.minIdleConns-stat.IdleConns())
562563
if toCreate > 0 {
563564
return p.createIdleResources(context.Background(), int(toCreate))
564565
}

0 commit comments

Comments
 (0)