From 8b2f29c0d2e571b45f004646d3b5e6bac1c2c419 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 25 Dec 2019 17:44:09 +0800 Subject: [PATCH] fix datarace on issue indexer queue (#9490) --- modules/indexer/code/indexer.go | 2 ++ modules/indexer/code/queue.go | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/indexer/code/indexer.go b/modules/indexer/code/indexer.go index 04d556f541..3f9461cd0e 100644 --- a/modules/indexer/code/indexer.go +++ b/modules/indexer/code/indexer.go @@ -38,6 +38,8 @@ func Init() { return } + initQueue(setting.Indexer.UpdateQueueLength) + ctx, cancel := context.WithCancel(context.Background()) graceful.GetManager().RunAtTerminate(ctx, func() { diff --git a/modules/indexer/code/queue.go b/modules/indexer/code/queue.go index 82cd8ded53..4eeb6ac7d4 100644 --- a/modules/indexer/code/queue.go +++ b/modules/indexer/code/queue.go @@ -21,8 +21,11 @@ type repoIndexerOperation struct { var repoIndexerOperationQueue chan repoIndexerOperation +func initQueue(queueLength int) { + repoIndexerOperationQueue = make(chan repoIndexerOperation, queueLength) +} + func processRepoIndexerOperationQueue(indexer Indexer) { - repoIndexerOperationQueue = make(chan repoIndexerOperation, setting.Indexer.UpdateQueueLength) for { select { case op := <-repoIndexerOperationQueue: -- 2.39.5