From 1ffc4ded4eb25bd2f5f47964fb861403958eba05 Mon Sep 17 00:00:00 2001 From: mhmxs Date: Tue, 8 Oct 2019 12:09:31 +0200 Subject: [PATCH] Solve race condition in fifo.process --- Makefile | 6 +++--- cncd/queue/fifo.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 090230dd7..5165f581c 100644 --- a/Makefile +++ b/Makefile @@ -21,13 +21,13 @@ format: @gofmt -w ${GOFILES_NOVENDOR} test-agent: - $(DOCKER_RUN) go test -timeout 30s github.com/laszlocph/woodpecker/cmd/drone-agent $(go list ./... | grep -v /vendor/) + $(DOCKER_RUN) go test -race -timeout 30s github.com/laszlocph/woodpecker/cmd/drone-agent $(go list ./... | grep -v /vendor/) test-server: - $(DOCKER_RUN) go test -timeout 30s github.com/laszlocph/woodpecker/cmd/drone-server + $(DOCKER_RUN) go test -race -timeout 30s github.com/laszlocph/woodpecker/cmd/drone-server test-lib: - $(DOCKER_RUN) go test -timeout 30s $(shell go list ./... | grep -v '/cmd/') + $(DOCKER_RUN) go test -race -timeout 30s $(shell go list ./... | grep -v '/cmd/') test: test-lib test-agent test-server diff --git a/cncd/queue/fifo.go b/cncd/queue/fifo.go index f6c064b2a..cd7964269 100644 --- a/cncd/queue/fifo.go +++ b/cncd/queue/fifo.go @@ -223,6 +223,9 @@ func (q *fifo) Resume() { // helper function that loops through the queue and attempts to // match the item to a single subscriber. func (q *fifo) process() { + q.Lock() + defer q.Unlock() + if q.paused { return } @@ -238,9 +241,6 @@ func (q *fifo) process() { } }() - q.Lock() - defer q.Unlock() - q.resubmitExpiredBuilds() q.filterWaiting() for pending, worker := q.assignToWorker(); pending != nil && worker != nil; pending, worker = q.assignToWorker() {