From 1e9ce2a5ac4092fdf61e293634e40bfb49595105 Mon Sep 17 00:00:00 2001 From: siddontang Date: Wed, 5 Oct 2016 19:08:31 +0800 Subject: [PATCH] timingwheel: fix time-skew error --- timingwheel/timingwheel.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/timingwheel/timingwheel.go b/timingwheel/timingwheel.go index 251993a..60f2956 100644 --- a/timingwheel/timingwheel.go +++ b/timingwheel/timingwheel.go @@ -51,9 +51,14 @@ func (w *TimingWheel) After(timeout time.Duration) <-chan struct{} { panic("timeout too much, over maxtimeout") } + index := int(timeout / w.interval) + if 0 < index { + index-- + } + w.Lock() - index := (w.pos + int(timeout/w.interval)) % len(w.cs) + index = (w.pos + index) % len(w.cs) b := w.cs[index]