Skip to content

Commit

Permalink
eth: fix potential data race
Browse files Browse the repository at this point in the history
> go test -race ./eth
...
WARNING: DATA RACE
Read at 0x00000268c128 by goroutine 10750:
  github.com/ethereum/go-ethereum/eth.(*chainSyncer).nextSyncOp()
      /home/ia/go/src/github.com/ethereum/go-ethereum/eth/sync.go:204 +0x216
  github.com/ethereum/go-ethereum/eth.(*chainSyncer).loop()
      /home/ia/go/src/github.com/ethereum/go-ethereum/eth/sync.go:146 +0x3f3
  github.com/ethereum/go-ethereum/eth.(*handler).Start.func3()
      /home/ia/go/src/github.com/ethereum/go-ethereum/eth/handler.go:604 +0x33

Previous write at 0x00000268c128 by goroutine 8683:
  github.com/ethereum/go-ethereum/eth.TestArtificialFinalityFeatureEnablingDisabling_StaleHead()
      /home/ia/go/src/github.com/ethereum/go-ethereum/eth/sync_test.go:344 +0x16a
  testing.tRunner()
      /home/ia/go1.21.2.linux-amd64/go/src/testing/testing.go:1595 +0x238
  testing.(*T).Run.func1()
      /home/ia/go1.21.2.linux-amd64/go/src/testing/testing.go:1648 +0x44

Date: 2024-03-12 11:33:33-06:00
Signed-off-by: meows <b5c6@protonmail.com>
  • Loading branch information
meowsbits committed Mar 12, 2024
1 parent 0e5f9f6 commit 0880c5f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions eth/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ func (cs *chainSyncer) nextSyncOp() *chainSyncOp {
} else if minPeers > cs.handler.maxPeers {
minPeers = cs.handler.maxPeers
}
if cs.handler.peers.len() < minArtificialFinalityPeers {
if cs.handler.chain.IsArtificialFinalityEnabled() {
if cs.handler.chain.IsArtificialFinalityEnabled() {
if cs.handler.peers.len() < minArtificialFinalityPeers {
// If artificial finality state is forcefully set (overridden) this will just be a noop.
cs.handler.chain.EnableArtificialFinality(false, "reason", "low peers", "peers", cs.handler.peers.len())
}
Expand Down

0 comments on commit 0880c5f

Please sign in to comment.