Failsafe timeout for background pool connections
Do not override existing connect timeout.
This commit is contained in:
+5
-5
@@ -208,14 +208,14 @@ func NewWithConfig(ctx context.Context, config *Config) (*Pool, error) {
|
|||||||
// see https://github.com/jackc/pgx/issues/1259
|
// see https://github.com/jackc/pgx/issues/1259
|
||||||
ctx = detachedCtx{ctx}
|
ctx = detachedCtx{ctx}
|
||||||
|
|
||||||
// But we do want to ensure that a connect won't hang forever.
|
connConfig := p.config.ConnConfig.Copy()
|
||||||
ctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
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 {
|
if p.beforeConnect != nil {
|
||||||
connConfig = p.config.ConnConfig.Copy()
|
|
||||||
if err := p.beforeConnect(ctx, connConfig); err != nil {
|
if err := p.beforeConnect(ctx, connConfig); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user