From 9d0e233e562dbc4b1761a600cb72c76104dfe711 Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Mon, 5 Dec 2022 18:19:06 +0800 Subject: [PATCH 1/3] ttl: fix data race in `del.go` --- ttl/ttlworker/del.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ttl/ttlworker/del.go b/ttl/ttlworker/del.go index d0bb651da8f41..eb86b1f3c6cf0 100644 --- a/ttl/ttlworker/del.go +++ b/ttl/ttlworker/del.go @@ -257,7 +257,7 @@ func (w *ttlDeleteWorker) loop() error { timer := time.NewTimer(w.retryBuffer.retryInterval) defer timer.Stop() - for w.status == workerStatusRunning { + for w.Status() == workerStatusRunning { select { case <-ctx.Done(): return nil From 488b9a50188f111775dac513ba5a6d905aed1dd4 Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Mon, 5 Dec 2022 18:29:30 +0800 Subject: [PATCH 2/3] update --- ttl/ttlworker/scan.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ttl/ttlworker/scan.go b/ttl/ttlworker/scan.go index 4d9f7924cd9a6..ef2d5bd6c2a05 100644 --- a/ttl/ttlworker/scan.go +++ b/ttl/ttlworker/scan.go @@ -250,7 +250,7 @@ func (w *ttlScanWorker) PollTaskResult() (*ttlScanTaskExecResult, bool) { func (w *ttlScanWorker) loop() error { ctx := w.baseWorker.ctx - for w.status == workerStatusRunning { + for w.Status() == workerStatusRunning { select { case <-ctx.Done(): return nil From 397e435b94cb258d6ddfe42dbcb455e3c657e56a Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Tue, 6 Dec 2022 09:57:48 +0800 Subject: [PATCH 3/3] fix block --- ttl/ttlworker/scan.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ttl/ttlworker/scan.go b/ttl/ttlworker/scan.go index ef2d5bd6c2a05..be77fdd317a87 100644 --- a/ttl/ttlworker/scan.go +++ b/ttl/ttlworker/scan.go @@ -212,21 +212,24 @@ func (w *ttlScanWorker) Idle() bool { func (w *ttlScanWorker) Schedule(task *ttlScanTask) error { w.Lock() - defer w.Unlock() if w.status != workerStatusRunning { + w.Unlock() return errors.New("worker is not running") } if w.curTaskResult != nil { + w.Unlock() return errors.New("the result of previous task has not been polled") } if w.curTask != nil { + w.Unlock() return errors.New("a task is running") } w.curTask = task w.curTaskResult = nil + w.Unlock() w.baseWorker.ch <- task return nil }