From 0e0ab48c92003dc65fbaf105224de13cd610bdb3 Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Tue, 2 Aug 2022 19:06:37 +0200 Subject: [PATCH] Re-add read lock --- internal/httputil/rate_limiting.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/httputil/rate_limiting.go b/internal/httputil/rate_limiting.go index 23e0dc9ab..699d3688a 100644 --- a/internal/httputil/rate_limiting.go +++ b/internal/httputil/rate_limiting.go @@ -69,6 +69,13 @@ func (l *RateLimits) Limit(req *http.Request, device *userapi.Device) *util.JSON return nil } + // Take a read lock out on the cleaner mutex. The cleaner expects to + // be able to take a write lock, which isn't possible while there are + // readers, so this has the effect of blocking the cleaner goroutine + // from doing its work until there are no requests in flight. + l.cleanMutex.RLock() + defer l.cleanMutex.RUnlock() + // First of all, work out if X-Forwarded-For was sent to us. If not // then we'll just use the IP address of the caller. var caller string