diff --git a/go/common/subscription/utils.go b/go/common/subscription/utils.go index fe50c09cdc..4179cf476c 100644 --- a/go/common/subscription/utils.go +++ b/go/common/subscription/utils.go @@ -17,10 +17,12 @@ import ( func ForwardFromChannels[R any](inputChannels []chan R, onMessage func(R) error, onBackendDisconnect func(), backendDisconnected *atomic.Bool, stopped *atomic.Bool, timeoutInterval time.Duration, logger gethlog.Logger) { inputCases := make([]reflect.SelectCase, len(inputChannels)+1) + cleanupTicker := time.NewTicker(2 * time.Second) + defer cleanupTicker.Stop() // create a ticker to handle cleanup, check the "stopped" flag and exit the goroutine inputCases[0] = reflect.SelectCase{ Dir: reflect.SelectRecv, - Chan: reflect.ValueOf(time.NewTicker(2 * time.Second).C), + Chan: reflect.ValueOf(cleanupTicker.C), } // create a select "case" for each input channel