X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b4e123604561174f928beab0f0a8fba7cbf2d33d..9fa65d7621853b24b7fb13acd44fedb28543b261:/lib/controller/handler.go diff --git a/lib/controller/handler.go b/lib/controller/handler.go index 5e9012949b..53125ae554 100644 --- a/lib/controller/handler.go +++ b/lib/controller/handler.go @@ -5,6 +5,7 @@ package controller import ( + "context" "database/sql" "errors" "net" @@ -49,6 +50,12 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { req.URL.Path = strings.Replace(req.URL.Path, "//", "/", -1) } } + if h.Cluster.HTTPRequestTimeout > 0 { + ctx, cancel := context.WithDeadline(req.Context(), time.Now().Add(time.Duration(h.Cluster.HTTPRequestTimeout))) + req = req.WithContext(ctx) + defer cancel() + } + h.handlerStack.ServeHTTP(w, req) } @@ -73,18 +80,15 @@ func (h *Handler) setup() { h.handlerStack = mux sc := *arvados.DefaultSecureClient - sc.Timeout = time.Duration(h.Cluster.HTTPRequestTimeout) sc.CheckRedirect = neverRedirect h.secureClient = &sc ic := *arvados.InsecureHTTPClient - ic.Timeout = time.Duration(h.Cluster.HTTPRequestTimeout) ic.CheckRedirect = neverRedirect h.insecureClient = &ic h.proxy = &proxy{ - Name: "arvados-controller", - RequestTimeout: time.Duration(h.Cluster.HTTPRequestTimeout), + Name: "arvados-controller", } } @@ -137,7 +141,7 @@ func (h *Handler) localClusterRequest(req *http.Request) (*http.Response, error) if insecure { client = h.insecureClient } - return h.proxy.ForwardRequest(req, urlOut, client) + return h.proxy.Do(req, urlOut, client) } func (h *Handler) proxyRailsAPI(w http.ResponseWriter, req *http.Request, next http.Handler) {