-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metrics: use atomic type (#27121) (#384)
We observe the data race warning when enabling metric WARNING: DATA RACE Read at 0x00c02cc7fe90 by goroutine 49: github.com/ethereum/go-ethereum/metrics.(*StandardMeter).Snapshot() github.com/ethereum/go-ethereum/metrics/meter.go:244 +0x6e github.com/ethereum/go-ethereum/metrics/prometheus.Handler.func1() github.com/ethereum/go-ethereum/metrics/prometheus/prometheus.go:55 +0x3c2 Previous write at 0x00c02cc7fe90 by goroutine 251: sync/atomic.AddInt64() runtime/race_amd64.s:289 +0xb sync/atomic.AddInt64() <autogenerated>:1 +0x1b github.com/ethereum/go-ethereum/p2p.(*rlpxTransport).WriteMsg() github.com/ethereum/go-ethereum/p2p/transport.go:103 +0x4c3 github.com/ethereum/go-ethereum/p2p.(*conn).WriteMsg() <autogenerated>:1 +0xb9 The data race happens on StandardMeter.snapshot.temp field. This field access does not follow the StandardMeter.lock but use atomic access. The write side in StandardMeter.Mark is atomic, however, the read side in StandardMeter.Snapshot is not. We cherry-pick this commit to correctly use atomic read of StandardMeter.snapshot.temp in StandardMeter.Snapshot. This commit also replaces the use of atomic.Load/StoreInt64 with atomic.Int64 type. Co-authored-by: s7v7nislands <[email protected]>
- Loading branch information
1 parent
f4a8cdb
commit d03c78b
Showing
4 changed files
with
31 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters