From 596d05bff5421a13939dcc86865a2e65b316ed3e Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Fri, 29 Jun 2018 20:56:10 +0200 Subject: [PATCH] check closed again before scheduling another task --- common/task/periodic.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 }