From e8c08ac18bf76928669bd2cc5edf676ff5c10588 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 19 Nov 2021 19:51:18 -0400 Subject: [PATCH] fix: invalid ticker usage --- waku/v2/node/wakunode2.go | 8 +++++--- waku/v2/protocol/store/message_queue.go | 13 ++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index 6a2802bc..614861c4 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -426,14 +426,16 @@ func (w *WakuNode) startStore() { // TODO: extract this to a function and run it when you go offline // TODO: determine if a store is listening to a topic go func() { + ticker := time.NewTicker(time.Second) + defer ticker.Stop() + for { - t := time.NewTicker(time.Second) peerVerif: for { select { case <-w.quit: return - case <-t.C: + case <-ticker.C: _, err := utils.SelectPeer(w.host, string(store.StoreID_v20beta3)) if err == nil { break peerVerif @@ -578,6 +580,7 @@ func (w *WakuNode) startKeepAlive(t time.Duration) { log.Info("Setting up ping protocol with duration of ", t) ticker := time.NewTicker(t) + defer ticker.Stop() go func() { for { @@ -595,7 +598,6 @@ func (w *WakuNode) startKeepAlive(t time.Duration) { } } case <-w.quit: - ticker.Stop() return } } diff --git a/waku/v2/protocol/store/message_queue.go b/waku/v2/protocol/store/message_queue.go index b47efddd..300be1cf 100644 --- a/waku/v2/protocol/store/message_queue.go +++ b/waku/v2/protocol/store/message_queue.go @@ -74,12 +74,15 @@ func (self *MessageQueue) cleanOlderRecords() { func (self *MessageQueue) checkForOlderRecords(d time.Duration) { ticker := time.NewTicker(d) + defer ticker.Stop() - select { - case <-self.quit: - return - case <-ticker.C: - self.cleanOlderRecords() + for { + select { + case <-self.quit: + return + case <-ticker.C: + self.cleanOlderRecords() + } } }