Pass the req context when pinging the DB

This commit is contained in:
Juan Font Alonso committed 2022-09-04 11:43:09 +02:00
1 parent 4527801d48
commit f23e9dc235
2 files changed
+3 -3

No files matched your search

+1 -1
View File
@@ -52,7 +52,7 @@ func (h *Headscale) HealthHandler(
} }
} }
if err := h.pingDB(); err != nil { if err := h.pingDB(req.Context()); err != nil {
respond(err) respond(err)
return return
+2 -2
View File
@@ -221,8 +221,8 @@ func (h *Headscale) setValue(key string, value string) error {
return nil return nil
} }
func (h *Headscale) pingDB() error { func (h *Headscale) pingDB(ctx context.Context) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second) ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel() defer cancel()
db, err := h.db.DB() db, err := h.db.DB()
if err != nil { if err != nil {