Skip to content

Commit

Permalink
Timeout DB connect after 10s
Browse files Browse the repository at this point in the history
  • Loading branch information
uhthomas committed Feb 18, 2021
1 parent ccc0eba commit ebef173
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/databaseutil/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/url"
"time"

"github.com/uhthomas/kipp/database"
"github.com/uhthomas/kipp/database/badger"
Expand All @@ -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)
Expand Down

0 comments on commit ebef173

Please sign in to comment.