From 8315bcd0d856b7ade3b6a2e1d44102e2a2ef3895 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Mon, 23 Aug 2021 18:19:14 +0200 Subject: [PATCH] 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. --- internal/http/stats/http-traffic-recorder.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/http/stats/http-traffic-recorder.go b/internal/http/stats/http-traffic-recorder.go index e5cfe3cfb..ef6e53930 100644 --- a/internal/http/stats/http-traffic-recorder.go +++ b/internal/http/stats/http-traffic-recorder.go @@ -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) }