From c44cb74cc728a8b9d3e634e02f14705440b5a3ff Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Sun, 5 Apr 2020 09:44:31 +0100 Subject: [PATCH] Propagate context to upstream request Propagates the context to upstream requests so that cancellation can cascade. Closes: #1501 by @SpaWn2KiLl which was not signed-off. Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- gateway/handlers/forwarding_proxy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/handlers/forwarding_proxy.go b/gateway/handlers/forwarding_proxy.go index 02d5ce53..17f4b672 100644 --- a/gateway/handlers/forwarding_proxy.go +++ b/gateway/handlers/forwarding_proxy.go @@ -123,7 +123,7 @@ func forwardRequest(w http.ResponseWriter, log.Printf("forwardRequest: %s %s\n", upstreamReq.Host, upstreamReq.URL.String()) } - ctx, cancel := context.WithTimeout(context.Background(), timeout) + ctx, cancel := context.WithTimeout(r.Context(), timeout) defer cancel() res, resErr := proxyClient.Do(upstreamReq.WithContext(ctx))