Skip to content

Commit d412076

Browse files
committed
fixup! fix(server): retry initial connection to postgres
1 parent dff6f63 commit d412076

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

cli/server.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -1753,15 +1753,10 @@ func connectToPostgres(ctx context.Context, logger slog.Logger, driver string, d
17531753
continue
17541754
}
17551755

1756-
pingCtx, pingCancel := context.WithTimeout(ctx, 5*time.Second)
1757-
err = sqlDB.PingContext(pingCtx)
1756+
err = pingPostgres(ctx, sqlDB)
17581757
if err != nil {
1759-
pingCancel()
17601758
continue
17611759
}
1762-
pingCancel()
1763-
1764-
err = nil
17651760
}
17661761
if err != nil {
17671762
return nil, xerrors.Errorf("connect to postgres; tries %d; last error: %w", tries, err)
@@ -1819,6 +1814,12 @@ func connectToPostgres(ctx context.Context, logger slog.Logger, driver string, d
18191814
return sqlDB, nil
18201815
}
18211816

1817+
func pingPostgres(ctx context.Context, db *sql.DB) error {
1818+
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
1819+
defer cancel()
1820+
return db.PingContext(ctx)
1821+
}
1822+
18221823
type HTTPServers struct {
18231824
HTTPUrl *url.URL
18241825
HTTPListener net.Listener

0 commit comments

Comments
 (0)