From d5ded2af2eab444a26f58a709217a150f333d3e5 Mon Sep 17 00:00:00 2001 From: NielsAD Date: Sat, 30 May 2020 22:41:13 +0200 Subject: [PATCH] Use req.Context() to cancel processing requests early --- fs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs.go b/fs.go index 8a24b9c..c84ab22 100644 --- a/fs.go +++ b/fs.go @@ -320,7 +320,7 @@ func (fs *CachedFS) serveCache(w http.ResponseWriter, r *http.Request) { return } - ctx, cancel := context.WithTimeout(context.Background(), fs.Timeout) + ctx, cancel := context.WithTimeout(r.Context(), fs.Timeout) defer cancel() p := cleanPath(r.URL.Path) @@ -465,7 +465,7 @@ func (fs *CachedFS) Sitemap(w http.ResponseWriter, r *http.Request) { return } - ctx, cancel := context.WithTimeout(context.Background(), fs.Timeout) + ctx, cancel := context.WithTimeout(r.Context(), fs.Timeout) defer cancel() var rows *sql.Rows