diff --git a/connection/h2mux.go b/connection/h2mux.go index b97208d3..cd91a67f 100644 --- a/connection/h2mux.go +++ b/connection/h2mux.go @@ -167,7 +167,8 @@ func (h *h2muxConnection) serveMuxer(ctx context.Context) error { } func (h *h2muxConnection) controlLoop(ctx context.Context, connectedFuse ConnectedFuse, isNamedTunnel bool) { - updateMetricsTickC := time.Tick(h.muxerConfig.MetricsUpdateFreq) + updateMetricsTicker := time.NewTicker(h.muxerConfig.MetricsUpdateFreq) + defer updateMetricsTicker.Stop() var shutdownCompleted <-chan struct{} for { select { @@ -191,7 +192,7 @@ func (h *h2muxConnection) controlLoop(ctx context.Context, connectedFuse Connect // don't wait for shutdown to finish when context is closed, this is the hard termination path return - case <-updateMetricsTickC: + case <-updateMetricsTicker.C: h.observer.metrics.updateMuxerMetrics(h.connIndexStr, h.muxer.Metrics()) } } diff --git a/h2mux/muxreader.go b/h2mux/muxreader.go index 2716508f..cf8d98f1 100644 --- a/h2mux/muxreader.go +++ b/h2mux/muxreader.go @@ -69,12 +69,13 @@ func (r *MuxReader) run(log *zerolog.Logger) error { // routine to periodically update bytesRead go func() { - tickC := time.Tick(updateFreq) + ticker := time.NewTicker(updateFreq) + defer ticker.Stop() for { select { case <-r.abortChan: return - case <-tickC: + case <-ticker.C: r.metricsUpdater.updateInBoundBytes(r.bytesRead.Count()) } } diff --git a/h2mux/muxwriter.go b/h2mux/muxwriter.go index 6956876e..c4d8fded 100644 --- a/h2mux/muxwriter.go +++ b/h2mux/muxwriter.go @@ -78,12 +78,13 @@ func (w *MuxWriter) run(log *zerolog.Logger) error { // routine to periodically communicate bytesWrote go func() { - tickC := time.Tick(updateFreq) + ticker := time.NewTicker(updateFreq) + defer ticker.Stop() for { select { case <-w.abortChan: return - case <-tickC: + case <-ticker.C: w.metricsUpdater.updateOutBoundBytes(w.bytesWrote.Count()) } }