TUN-4456: Replaced instances of Tick() with Ticker() in h2mux paths
time.Tick() does not get garbage collected because the channel underneath never gets deleted and the underlying Ticker can never be recovered by the garbage collector. We replace this with NewTicker() to avoid this.
This commit is contained in:
parent
f99ae90ca1
commit
951d13d76c
|
@ -167,7 +167,8 @@ func (h *h2muxConnection) serveMuxer(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *h2muxConnection) controlLoop(ctx context.Context, connectedFuse ConnectedFuse, isNamedTunnel bool) {
|
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{}
|
var shutdownCompleted <-chan struct{}
|
||||||
for {
|
for {
|
||||||
select {
|
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
|
// don't wait for shutdown to finish when context is closed, this is the hard termination path
|
||||||
return
|
return
|
||||||
|
|
||||||
case <-updateMetricsTickC:
|
case <-updateMetricsTicker.C:
|
||||||
h.observer.metrics.updateMuxerMetrics(h.connIndexStr, h.muxer.Metrics())
|
h.observer.metrics.updateMuxerMetrics(h.connIndexStr, h.muxer.Metrics())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,12 +69,13 @@ func (r *MuxReader) run(log *zerolog.Logger) error {
|
||||||
|
|
||||||
// routine to periodically update bytesRead
|
// routine to periodically update bytesRead
|
||||||
go func() {
|
go func() {
|
||||||
tickC := time.Tick(updateFreq)
|
ticker := time.NewTicker(updateFreq)
|
||||||
|
defer ticker.Stop()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-r.abortChan:
|
case <-r.abortChan:
|
||||||
return
|
return
|
||||||
case <-tickC:
|
case <-ticker.C:
|
||||||
r.metricsUpdater.updateInBoundBytes(r.bytesRead.Count())
|
r.metricsUpdater.updateInBoundBytes(r.bytesRead.Count())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,12 +78,13 @@ func (w *MuxWriter) run(log *zerolog.Logger) error {
|
||||||
|
|
||||||
// routine to periodically communicate bytesWrote
|
// routine to periodically communicate bytesWrote
|
||||||
go func() {
|
go func() {
|
||||||
tickC := time.Tick(updateFreq)
|
ticker := time.NewTicker(updateFreq)
|
||||||
|
defer ticker.Stop()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-w.abortChan:
|
case <-w.abortChan:
|
||||||
return
|
return
|
||||||
case <-tickC:
|
case <-ticker.C:
|
||||||
w.metricsUpdater.updateOutBoundBytes(w.bytesWrote.Count())
|
w.metricsUpdater.updateOutBoundBytes(w.bytesWrote.Count())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue