From 206dda158036e7e892eaabcaab3cd2ef3d64a5d9 Mon Sep 17 00:00:00 2001 From: defiQUG Date: Fri, 26 Jun 2026 02:03:24 -0700 Subject: [PATCH] Propagate request context in block REST handlers. 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 --- backend/api/rest/blocks.go | 4 ++-- backend/go.mod | 2 +- backend/go.sum | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/backend/api/rest/blocks.go b/backend/api/rest/blocks.go index ea91192..446a055 100644 --- a/backend/api/rest/blocks.go +++ b/backend/api/rest/blocks.go @@ -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 := ` diff --git a/backend/go.mod b/backend/go.mod index 17a15dd..5e4e864 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -42,7 +42,7 @@ require ( github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.20.5 // indirect - github.com/rogpeppe/go-internal v1.10.0 // indirect + github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect github.com/supranational/blst v0.3.11 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect diff --git a/backend/go.sum b/backend/go.sum index 4f8c1b3..13e3dae 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -145,8 +145,7 @@ github.com/redis/go-redis/v9 v9.17.2 h1:P2EGsA4qVIM3Pp+aPocCJ7DguDHhqrXNhVcEp4Vi github.com/redis/go-redis/v9 v9.17.2/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0//kSOd3370= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= -github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=