From 4dc694411f3a4537c03aa95f69105e546355b516 Mon Sep 17 00:00:00 2001 From: Anker Jam Date: Mon, 5 Oct 2020 00:16:58 +0800 Subject: [PATCH] fix deadlock in task module --- pkg/task/task.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/task/task.go b/pkg/task/task.go index e3a8bba4..4835ad24 100644 --- a/pkg/task/task.go +++ b/pkg/task/task.go @@ -451,6 +451,11 @@ func run() { taskLock.Unlock() continue case <-stop: + taskLock.Lock() + if isstart { + isstart = false + } + taskLock.Unlock() return } } @@ -458,13 +463,7 @@ func run() { // StopTask stop all tasks func StopTask() { - taskLock.Lock() - defer taskLock.Unlock() - if isstart { - isstart = false - stop <- true - } - + stop <- true } // AddTask add task with name