From d016bf111b589e884957256fb1af3f73ba42f656 Mon Sep 17 00:00:00 2001 From: YongHaoHu Date: Mon, 15 Jun 2020 18:37:12 +0800 Subject: [PATCH] metrics: Fix ctx scope. --- metrics/handler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/metrics/handler.go b/metrics/handler.go index 71b1d7418..b7caf0876 100644 --- a/metrics/handler.go +++ b/metrics/handler.go @@ -11,9 +11,9 @@ import ( // ResourceMiddleware to make sure update resource correct func (m *Metrics) ResourceMiddleware(cluster cluster.Cluster) func(http.Handler) http.Handler { return func(h http.Handler) http.Handler { - ctx, cancel := context.WithTimeout(context.Background(), m.Config.GlobalTimeout) - defer cancel() return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ctx, cancel := context.WithTimeout(context.Background(), m.Config.GlobalTimeout) + defer cancel() pods, err := cluster.ListPods(ctx) if err != nil { log.Errorf("[ResourceMiddleware] List pods err %v", err)