From ebef1731206f072a040ed6acfdf6a4e183f4c7fa Mon Sep 17 00:00:00 2001 From: Thomas <9749173+uhthomas@users.noreply.github.com> Date: Thu, 18 Feb 2021 18:38:15 +0000 Subject: [PATCH] Timeout DB connect after 10s --- internal/databaseutil/parse.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/databaseutil/parse.go b/internal/databaseutil/parse.go index fda21663..cb1c168f 100644 --- a/internal/databaseutil/parse.go +++ b/internal/databaseutil/parse.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/url" + "time" "github.com/uhthomas/kipp/database" "github.com/uhthomas/kipp/database/badger" @@ -20,6 +21,8 @@ func Parse(ctx context.Context, s string) (database.Database, error) { case "": return badger.Open(u.Path) case "psql", "postgres", "postgresql": + ctx, cancel := context.WithTimeout(ctx, 10*time.Second) + defer cancel() return sql.Open(ctx, "pgx", u.String()) } return nil, fmt.Errorf("invalid scheme: %s", u.Scheme)