From 8926cbe36817ac756318fbaea40c41dca479c4af Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 15 Oct 2019 18:55:32 +0300 Subject: [PATCH] core: fix potential data race in logging code Spotted in CircleCI build with Go 1.12: WARNING: DATA RACE Write at 0x00c00011095c by goroutine 88: sync/atomic.SwapInt32() /usr/local/go/src/runtime/race_amd64.s:249 +0xb github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).persist() /go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:483 +0x172 github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).Run.func2() /go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:191 +0x50 Previous read at 0x00c00011095c by goroutine 64: github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).persist() /go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:492 +0x4be github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).Run.func2() /go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:191 +0x50 Goroutine 88 (running) created at: github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).Run() /go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:190 +0x264 Goroutine 64 (finished) created at: github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).Run() /go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:190 +0x264 --- pkg/core/blockchain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 8b7145199..50abcd962 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -489,7 +489,7 @@ func (bc *Blockchain) persist(ctx context.Context) error { "persistedKeys": persisted, "headerHeight": bc.HeaderHeight(), "blockHeight": bc.BlockHeight(), - "persistedHeight": bc.persistedHeight, + "persistedHeight": atomic.LoadUint32(&bc.persistedHeight), "took": time.Since(start), }).Info("blockchain persist completed") }