From dc081e30ba3d91db5f0abccb202e1f6aa9671b14 Mon Sep 17 00:00:00 2001 From: Roman Behma <13855864+begmaroman@users.noreply.github.com> Date: Thu, 2 May 2024 13:58:07 +0200 Subject: [PATCH] Fixed superfluous response in the health handler (#140) --- cmd/main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 52cd744..61503bb 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -307,19 +307,21 @@ func useLocalAuth(c *config.Config) (*bind.TransactOpts, common.Address, error) // healthHandler returns a handler that checks the health of the application func healthHandler(storage *db.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - txctx := context.Background() - dbtx, err := storage.BeginStateTransaction(txctx) + ctx := r.Context() + + dbtx, err := storage.BeginStateTransaction(ctx) if err != nil { w.WriteHeader(http.StatusInternalServerError) return } - if err = dbtx.Rollback(txctx); err != nil { + if err = dbtx.Rollback(ctx); err != nil { w.WriteHeader(http.StatusInternalServerError) return } - _, _ = w.Write([]byte("Healthy")) - w.WriteHeader(http.StatusOK) + if _, err = w.Write([]byte("Healthy")); err != nil { + log.Errorf("failed to write response in health check handler: %s", err) + } } }