From 4809c8f71001c3e1dd49c62ea467a65aac1e94f6 Mon Sep 17 00:00:00 2001 From: luogz17 Date: Sat, 9 Dec 2023 00:46:41 +0800 Subject: [PATCH] fix(workerpool.go): move taskQueueChan initialization in Run method, if AddTask is called before Run, will cause a panic. --- common/utils/workerpool/workerpool.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/utils/workerpool/workerpool.go b/common/utils/workerpool/workerpool.go index ee39647e7b..a779c4f690 100644 --- a/common/utils/workerpool/workerpool.go +++ b/common/utils/workerpool/workerpool.go @@ -15,14 +15,13 @@ type WorkerPool struct { func NewWorkerPool(maxWorker int) *WorkerPool { return &WorkerPool{ maxWorker: maxWorker, - taskQueueChan: nil, + taskQueueChan: make(chan func()), wg: sync.WaitGroup{}, } } // Run runs WorkerPool func (vwp *WorkerPool) Run() { - vwp.taskQueueChan = make(chan func()) for i := 0; i < vwp.maxWorker; i++ { go func() { for task := range vwp.taskQueueChan {