From 50f1c78944650181735b545bf31939cb36182ffc Mon Sep 17 00:00:00 2001 From: frozen <355847+Frozen@users.noreply.github.com> Date: Wed, 2 Nov 2022 18:37:20 +0800 Subject: [PATCH] Added locks detected by race. --- consensus/consensus_v2.go | 5 ++++- scripts/go_executable_build.sh | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/consensus/consensus_v2.go b/consensus/consensus_v2.go index 710c4e72b..4575e197e 100644 --- a/consensus/consensus_v2.go +++ b/consensus/consensus_v2.go @@ -310,16 +310,19 @@ func (consensus *Consensus) Start( case <-stopChan: return case <-ticker.C: + consensus.mutex.Lock() consensus.tick() + consensus.mutex.Unlock() } } }() + consensus.mutex.Lock() consensus.consensusTimeout[timeoutBootstrap].Start() consensus.getLogger().Info().Msg("[ConsensusMainLoop] Start bootstrap timeout (only once)") - // Set up next block due time. consensus.NextBlockDue = time.Now().Add(consensus.BlockPeriod) + consensus.mutex.Unlock() }() if consensus.dHelper != nil { diff --git a/scripts/go_executable_build.sh b/scripts/go_executable_build.sh index 6331aa522..9d111d79f 100755 --- a/scripts/go_executable_build.sh +++ b/scripts/go_executable_build.sh @@ -120,6 +120,7 @@ function build_only if [ "$STATIC" == "true" ]; then env GOOS=$GOOS GOARCH=$GOARCH go build $VERBOSE -gcflags="${GO_GCFLAGS}" -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY} -w -extldflags \"-static -lm\"" -o $BINDIR/$bin $RACE $TRACEPTR ${SRC[$bin]} else +# env GOOS=$GOOS GOARCH=$GOARCH go build -race $VERBOSE -gcflags="${GO_GCFLAGS}" -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY}" -o $BINDIR/$bin $RACE $TRACEPTR ${SRC[$bin]} env GOOS=$GOOS GOARCH=$GOARCH go build $VERBOSE -gcflags="${GO_GCFLAGS}" -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY}" -o $BINDIR/$bin $RACE $TRACEPTR ${SRC[$bin]} fi fi