From ef4542e7781f1bf661878002f25f630570e20fb5 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Fri, 22 Jun 2018 11:19:33 +0200 Subject: [PATCH] fix race condition in ActivityTimer --- common/signal/timer.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/common/signal/timer.go b/common/signal/timer.go index 67ec5f13a..4182d4b2d 100644 --- a/common/signal/timer.go +++ b/common/signal/timer.go @@ -56,18 +56,20 @@ func (t *ActivityTimer) SetTimeout(timeout time.Duration) { return } + checkTask := &task.Periodic{ + Interval: timeout, + Execute: t.check, + } + t.Lock() if t.checkTask != nil { t.checkTask.Close() // nolint: errcheck } - t.checkTask = &task.Periodic{ - Interval: timeout, - Execute: t.check, - } + t.checkTask = checkTask t.Unlock() t.Update() - common.Must(t.checkTask.Start()) + common.Must(checkTask.Start()) } func CancelAfterInactivity(ctx context.Context, cancel context.CancelFunc, timeout time.Duration) *ActivityTimer {