From 7a737433d39189529ddc963c0519f980c9cfc548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?rich=CE=9Brd?= Date: Wed, 2 Oct 2024 09:26:58 -0400 Subject: [PATCH] fix_: bandwidthCounter should be reset each time it is retrieved otherwise it behaves like an accumulator (#5898) --- wakuv2/waku.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/wakuv2/waku.go b/wakuv2/waku.go index c61acd14f..230fd0bf2 100644 --- a/wakuv2/waku.go +++ b/wakuv2/waku.go @@ -519,20 +519,14 @@ func (w *Waku) telemetryBandwidthStats(telemetryServerURL string) { ticker := time.NewTicker(time.Second * 20) defer ticker.Stop() - today := time.Now() - for { select { case <-w.ctx.Done(): return - case now := <-ticker.C: - // Reset totals when day changes - if now.Day() != today.Day() { - today = now - w.bandwidthCounter.Reset() - } - - go telemetry.PushProtocolStats(w.bandwidthCounter.GetBandwidthByProtocol()) + case <-ticker.C: + bandwidthPerProtocol := w.bandwidthCounter.GetBandwidthByProtocol() + w.bandwidthCounter.Reset() + go telemetry.PushProtocolStats(bandwidthPerProtocol) } } }