From 7ce634d62b474a0a1e4683138d7ee1258bd4f34e Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 6 Aug 2022 06:22:17 -0500 Subject: [PATCH] Ensure there is a timeout for background pool connections --- pgxpool/pool.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pgxpool/pool.go b/pgxpool/pool.go index 9a12fb8ee..d2155043e 100644 --- a/pgxpool/pool.go +++ b/pgxpool/pool.go @@ -214,6 +214,10 @@ 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 if p.beforeConnect != nil {