fix: the runtime cycle log is keyed by rules and bounded (WR-13)
redirectHopsLogged was a never-evicted map keyed by the anonymous request's URL with its query, so requests to a looping address with fresh query strings grew it without limit and logged each one. The log is now keyed by the cycle's rule ids, repeats at most once an hour and starts over at 1024 keys.
This commit is contained in:
@@ -203,3 +203,34 @@ func TestRedirectGraph(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestCycleLogBounded: the runtime cycle log is keyed by the cycle's rules,
|
||||
// not the request URL, and never holds more than maxCycleLog keys (WR-13).
|
||||
func TestCycleLogBounded(t *testing.T) {
|
||||
set := NewRedirectSet([]models.Redirect{rd(1, "/la", "/lb"), rd(2, "/lb", "/la")})
|
||||
ch, err := set.Follow(rdSite, "/la", "", MaxRedirectHops)
|
||||
if err != nil || !ch.Loop {
|
||||
t.Fatalf("chain = %+v, %v; want a loop", ch, err)
|
||||
}
|
||||
cycleLog.Lock()
|
||||
cycleLog.seen = nil
|
||||
cycleLog.Unlock()
|
||||
for i := 0; i < 5000; i++ {
|
||||
logRedirectCycle(rdSite+"/la?x="+strconv.Itoa(i), ch)
|
||||
}
|
||||
cycleLog.Lock()
|
||||
n := len(cycleLog.seen)
|
||||
cycleLog.Unlock()
|
||||
if n != 1 {
|
||||
t.Fatalf("cycle log keys after one cycle from 5000 URLs = %d, want 1", n)
|
||||
}
|
||||
for i := 0; i < maxCycleLog+10; i++ {
|
||||
logRedirectCycle("/x", Chain{Hops: []RedirectHit{{Rule: rd(uint(100+i), "/a", "/b")}}})
|
||||
}
|
||||
cycleLog.Lock()
|
||||
n = len(cycleLog.seen)
|
||||
cycleLog.Unlock()
|
||||
if n > maxCycleLog {
|
||||
t.Fatalf("cycle log keys = %d, want at most %d", n, maxCycleLog)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user