Skip to content

Commit

Permalink
Failsafe timeout for background pool connections
Browse files Browse the repository at this point in the history
Do not override existing connect timeout.
  • Loading branch information
jackc committed Aug 13, 2022
1 parent 6871a0c commit 1d748d9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pgxpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ func ConnectConfig(ctx context.Context, config *Config) (*Pool, error) {
// see https://github.com/jackc/pgx/issues/1259
ctx = detachedCtx{ctx}

// But we do want to ensure that a connect won't hang forever.
ctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
defer cancel()
connConfig := p.config.ConnConfig.Copy()

connConfig := p.config.ConnConfig
// But we do want to ensure that a connect won't hang forever.
if connConfig.ConnectTimeout <= 0 {
connConfig.ConnectTimeout = 2 * time.Minute
}

if p.beforeConnect != nil {
connConfig = p.config.ConnConfig.Copy()
if err := p.beforeConnect(ctx, connConfig); err != nil {
return nil, err
}
Expand Down

0 comments on commit 1d748d9

Please sign in to comment.