Fix TrafficMeter data race (#13041)

When reading `TrafficMeter` values, there was a value receiver.

This means that receivers are copied unsafely when invoked.

Fixes race seen with `-race` build.
This commit is contained in:
Klaus Post 2021-08-23 18:19:14 +02:00 committed by GitHub
parent 7fb9301c03
commit 8315bcd0d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,7 +38,7 @@ func (r *IncomingTrafficMeter) Read(p []byte) (n int, err error) {
}
// BytesCount returns the number of transferred bytes
func (r IncomingTrafficMeter) BytesCount() int64 {
func (r *IncomingTrafficMeter) BytesCount() int64 {
return atomic.LoadInt64(&r.countBytes)
}
@ -62,6 +62,6 @@ func (w *OutgoingTrafficMeter) Flush() {
}
// BytesCount returns the number of transferred bytes
func (w OutgoingTrafficMeter) BytesCount() int64 {
func (w *OutgoingTrafficMeter) BytesCount() int64 {
return atomic.LoadInt64(&w.countBytes)
}