types/logger: fix deadlock in the burst case.

Fixes #365.

Signed-off-by: David Anderson <danderson@tailscale.com>
pull/366/head
David Anderson 5 years ago
parent ccbd0937d0
commit 48b1e85e8a

@ -72,7 +72,6 @@ func RateLimitedFn(logf Logf, f float64, b int, m int) Logf {
if ok { if ok {
msgCache.MoveToFront(rl.ele) msgCache.MoveToFront(rl.ele)
if rl.lim.Allow() { if rl.lim.Allow() {
mu.Lock()
rl.msgBlocked = false rl.msgBlocked = false
mu.Unlock() mu.Unlock()
logf(format, args...) logf(format, args...)

@ -41,13 +41,15 @@ func TestRateLimiter(t *testing.T) {
want := []string{ want := []string{
"boring string with constant formatting (constant)", "boring string with constant formatting (constant)",
"templated format string no. 0", "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: 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", "Make sure this string makes it through the rest (that are blocked) 4",
"4 shouldn't get filtered.", "4 shouldn't get filtered.",
} }
lg := RateLimitedFn(logTester(want), 1, 1, 50) lg := RateLimitedFn(logTester(want), 1, 2, 50)
var prefixed Logf var prefixed Logf
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
lg("boring string with constant formatting %s", "(constant)") lg("boring string with constant formatting %s", "(constant)")

Loading…
Cancel
Save