Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Fixed superfluous response in the health handler (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
begmaroman authored May 2, 2024
1 parent 457cdc3 commit dc081e3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit dc081e3

Please sign in to comment.