types/logger: fix deadlock in the burst case.

Fixes #365.

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson 2020-05-09 02:52:03 +00:00
parent ccbd0937d0
commit 48b1e85e8a
2 changed files with 4 additions and 3 deletions

View File

@ -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...)

View File

@ -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)")