X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/afbea0d985d273232291f03f343baed727393108..db118cca358662e57a3dd0c1186dce1f0a62ca52:/lib/controller/handler.go diff --git a/lib/controller/handler.go b/lib/controller/handler.go index 07e6514810..5d6bd9570c 100644 --- a/lib/controller/handler.go +++ b/lib/controller/handler.go @@ -135,6 +135,7 @@ func (h *Handler) setup() { hs := http.NotFoundHandler() hs = prepend(hs, h.proxyRailsAPI) + hs = prepend(hs, h.limitLogCreateRequests) hs = h.setupProxyRemoteCluster(hs) hs = prepend(hs, oidcAuthorizer.Middleware) mux.Handle("/", hs) @@ -152,11 +153,6 @@ func (h *Handler) setup() { if logCreateLimit == 0 && h.Cluster.API.LogCreateRequestFraction > 0 { logCreateLimit = 1 } - if logCreateLimit == 0 { - // can't have unlimited size channels, so just make - // the buffer size really big. - logCreateLimit = 4096 - } h.limitLogCreate = make(chan struct{}, logCreateLimit) h.proxy = &proxy{ @@ -195,11 +191,11 @@ func (h *Handler) localClusterRequest(req *http.Request) (*http.Response, error) } func (h *Handler) limitLogCreateRequests(w http.ResponseWriter, req *http.Request, next http.Handler) { - if req.Method == http.MethodPost && strings.HasPrefix(req.URL.Path, "/arvados/v1/logs") { + if cap(h.limitLogCreate) > 0 && req.Method == http.MethodPost && strings.HasPrefix(req.URL.Path, "/arvados/v1/logs") { select { case h.limitLogCreate <- struct{}{}: + defer func() { <-h.limitLogCreate }() next.ServeHTTP(w, req) - <-h.limitLogCreate default: http.Error(w, "Excess log messages", http.StatusServiceUnavailable) }