From 70e694ee76f09058ea38c9ba81b4aa621bd54df1 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Tue, 6 Dec 2016 01:39:04 -0800 Subject: [PATCH] Fix ThrottleTimer null-pointer error / race condition --- throttle_timer.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/throttle_timer.go b/throttle_timer.go index 0966e913..38ef4e9a 100644 --- a/throttle_timer.go +++ b/throttle_timer.go @@ -26,7 +26,9 @@ func NewThrottleTimer(name string, dur time.Duration) *ThrottleTimer { var ch = make(chan struct{}) var quit = make(chan struct{}) var t = &ThrottleTimer{Name: name, Ch: ch, dur: dur, quit: quit} + t.mtx.Lock() t.timer = time.AfterFunc(dur, t.fireRoutine) + t.mtx.Unlock() t.timer.Stop() return t }