From 48b1e85e8ad541f231a7a18b924af7049c5d3d15 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 9 May 2020 02:52:03 +0000 Subject: [PATCH] types/logger: fix deadlock in the burst case. Fixes #365. Signed-off-by: David Anderson --- types/logger/logger.go | 1 - types/logger/logger_test.go | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/types/logger/logger.go b/types/logger/logger.go index c60282ddb..0b0a93c79 100644 --- a/types/logger/logger.go +++ b/types/logger/logger.go @@ -72,7 +72,6 @@ func RateLimitedFn(logf Logf, f float64, b int, m int) Logf { if ok { msgCache.MoveToFront(rl.ele) if rl.lim.Allow() { - mu.Lock() rl.msgBlocked = false mu.Unlock() logf(format, args...) diff --git a/types/logger/logger_test.go b/types/logger/logger_test.go index f1a5be2cf..1f7ab4f07 100644 --- a/types/logger/logger_test.go +++ b/types/logger/logger_test.go @@ -41,13 +41,15 @@ func TestRateLimiter(t *testing.T) { want := []string{ "boring string with constant formatting (constant)", "templated format string no. 0", + "boring string with constant formatting (constant)", + "templated format string no. 1", "Repeated messages were suppressed by rate limiting. Original message: boring string with constant formatting (constant)", - "Repeated messages were suppressed by rate limiting. Original message: templated format string no. 1", + "Repeated messages were suppressed by rate limiting. Original message: templated format string no. 2", "Make sure this string makes it through the rest (that are blocked) 4", "4 shouldn't get filtered.", } - lg := RateLimitedFn(logTester(want), 1, 1, 50) + lg := RateLimitedFn(logTester(want), 1, 2, 50) var prefixed Logf for i := 0; i < 10; i++ { lg("boring string with constant formatting %s", "(constant)")