Skip to content

Commit

Permalink
fix: filter ping timeout and retry in case of failure (#1166)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyaprem committed Jul 24, 2024
1 parent 75047cc commit 58d9721
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
1 change: 0 additions & 1 deletion waku/v2/api/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"go.uber.org/zap"
)

const FilterPingTimeout = 5 * time.Second
const MultiplexChannelBuffer = 100

type FilterConfig struct {
Expand Down
26 changes: 18 additions & 8 deletions waku/v2/protocol/filter/filter_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"go.uber.org/zap"
)

const PingTimeout = 5 * time.Second

func (wf *WakuFilterLightNode) PingPeers() {
//Send a ping to all the peers and report their status to corresponding subscriptions
// Alive or not or set state of subcription??
Expand All @@ -17,17 +19,23 @@ func (wf *WakuFilterLightNode) PingPeers() {
}

func (wf *WakuFilterLightNode) PingPeer(peer peer.ID) {
ctxWithTimeout, cancel := context.WithTimeout(wf.CommonService.Context(), wf.peerPingInterval)
ctxWithTimeout, cancel := context.WithTimeout(wf.CommonService.Context(), PingTimeout)
defer cancel()
err := wf.Ping(ctxWithTimeout, peer)
if err != nil {
wf.log.Warn("Filter ping failed towards peer", zap.Stringer("peer", peer), zap.Error(err))

subscriptions := wf.subscriptions.GetAllSubscriptionsForPeer(peer)
for _, subscription := range subscriptions {
wf.log.Debug("Notifying sub closing", zap.String("subID", subscription.ID))
//Indicating that subscription is closing,
subscription.SetClosing()
//quickly retry ping again before marking subscription as failure
//Note that PingTimeout is a fraction of PingInterval so this shouldn't cause parallel pings being sent.
ctxWithTimeout, cancel := context.WithTimeout(wf.CommonService.Context(), PingTimeout)
defer cancel()
err = wf.Ping(ctxWithTimeout, peer)
if err != nil {
subscriptions := wf.subscriptions.GetAllSubscriptionsForPeer(peer)
for _, subscription := range subscriptions {
wf.log.Debug("Notifying sub closing", zap.String("subID", subscription.ID))
//Indicating that subscription is closing,
subscription.SetClosing()
}
}
}
}
Expand All @@ -39,7 +47,9 @@ func (wf *WakuFilterLightNode) FilterHealthCheckLoop() {
for {
select {
case <-ticker.C:
wf.PingPeers()
if wf.onlineChecker.IsOnline() {
wf.PingPeers()
}
case <-wf.CommonService.Context().Done():
return
}
Expand Down

0 comments on commit 58d9721

Please sign in to comment.