mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
types/logger: fix deadlock in the burst case.
Fixes #365. Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
ccbd0937d0
commit
48b1e85e8a
@ -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...)
|
||||
|
@ -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)")
|
||||
|
Loading…
Reference in New Issue
Block a user