diff --git a/common/signal/timer.go b/common/signal/timer.go index ece9f496..da108f2c 100644 --- a/common/signal/timer.go +++ b/common/signal/timer.go @@ -56,20 +56,22 @@ func (t *ActivityTimer) SetTimeout(timeout time.Duration) { return } + t.Lock() + defer t.Unlock() + if t.onTimeout == nil { + return + } checkTask := &task.Periodic{ Interval: timeout, Execute: t.check, } - t.Lock() - if t.checkTask != nil { t.checkTask.Close() } t.checkTask = checkTask t.Update() common.Must(checkTask.Start()) - t.Unlock() } func CancelAfterInactivity(ctx context.Context, cancel context.CancelFunc, timeout time.Duration) *ActivityTimer {