mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-23 14:53:10 -06:00
Use PingContext instead of Ping
This commit is contained in:
parent
3243a42a49
commit
010511be13
|
|
@ -15,6 +15,7 @@
|
|||
package httputil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
|
@ -42,12 +43,12 @@ func HealthCheckHandler(dbConfig ...config.DatabaseOptions) http.HandlerFunc {
|
|||
conns[i] = c
|
||||
}
|
||||
|
||||
return func(rw http.ResponseWriter, _ *http.Request) {
|
||||
return func(rw http.ResponseWriter, req *http.Request) {
|
||||
resp := &healthResponse{
|
||||
Code: http.StatusOK,
|
||||
FirstError: "",
|
||||
}
|
||||
err := dbPingCheck(conns, resp)
|
||||
err := dbPingCheck(conns, resp, req.Context())
|
||||
if err != nil {
|
||||
rw.WriteHeader(resp.Code)
|
||||
}
|
||||
|
|
@ -58,10 +59,10 @@ func HealthCheckHandler(dbConfig ...config.DatabaseOptions) http.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func dbPingCheck(conns []*sql.DB, resp *healthResponse) error {
|
||||
func dbPingCheck(conns []*sql.DB, resp *healthResponse, ctx context.Context) error {
|
||||
// check every database connection
|
||||
for _, conn := range conns {
|
||||
if err := conn.Ping(); err != nil {
|
||||
if err := conn.PingContext(ctx); err != nil {
|
||||
resp.Code = http.StatusInternalServerError
|
||||
resp.FirstError = err.Error()
|
||||
return err
|
||||
|
|
|
|||
Loading…
Reference in a new issue