Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a8464cd

Browse files
fsaminsguiheux
authored andcommitted
fix(api): force context cancellation (#4633)
1 parent 9d5dcd7 commit a8464cd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

engine/api/router.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ func (r *Router) Handle(uri string, handlers ...*service.HandlerConfig) {
201201
}
202202

203203
f := func(w http.ResponseWriter, req *http.Request) {
204-
ctx := req.Context()
204+
ctx, cancel := context.WithCancel(req.Context())
205+
defer cancel()
205206

206207
responseWriter := &trackingResponseWriter{
207208
writer: w,
@@ -228,7 +229,7 @@ func (r *Router) Handle(uri string, handlers ...*service.HandlerConfig) {
228229
w.WriteHeader(http.StatusOK)
229230
return
230231
}
231-
observability.Record(ctx, r.Stats.Hits, 1)
232+
observability.Record(r.Background, r.Stats.Hits, 1)
232233

233234
//Get route configuration
234235
rc := cfg.Config[req.Method]

0 commit comments

Comments
 (0)