Propagate request context in block REST handlers.
Some checks failed
Deploy Explorer Live / deploy (push) Failing after 24s

Use r.Context() for DB query timeouts so client disconnects cancel in-flight block lookups instead of running against a detached background context.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
defiQUG
2026-06-26 02:03:24 -07:00
parent 890ebe3727
commit 206dda1580
3 changed files with 4 additions and 5 deletions

View File

@@ -21,7 +21,7 @@ func (s *Server) handleGetBlockByNumber(w http.ResponseWriter, r *http.Request,
}
// Add query timeout
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second)
defer cancel()
query := `
@@ -89,7 +89,7 @@ func (s *Server) handleGetBlockByHash(w http.ResponseWriter, r *http.Request, ha
}
// Add query timeout
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second)
defer cancel()
query := `