diff --git a/common/task/periodic.go b/common/task/periodic.go index 4379830a..305a4933 100644 --- a/common/task/periodic.go +++ b/common/task/periodic.go @@ -42,12 +42,17 @@ func (t *Periodic) checkedExecute() error { } t.access.Lock() + defer t.access.Unlock() + + if t.closed { + return nil + } + t.timer = time.AfterFunc(t.Interval, func() { if err := t.checkedExecute(); err != nil && t.OnError != nil { t.OnError(err) } }) - t.access.Unlock() return nil }