fix race condition in ActivityTimer

pull/1162/merge
Darien Raymond 2018-06-22 11:19:33 +02:00
parent 57d6808882
commit ef4542e778
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
1 changed files with 7 additions and 5 deletions

View File

@ -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 {