Skip to content

Commit

Permalink
considering case of node not started in keepalive loop
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer committed Oct 29, 2024
1 parent 7d8b186 commit 3a72eb0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions waku/node/waku_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1199,9 +1199,11 @@ proc fetchPeerExchangePeers*(

proc peerExchangeLoop(node: WakuNode) {.async.} =
while true:
await sleepAsync(1.minutes)
if not node.started:
continue
(await node.fetchPeerExchangePeers()).isOkOr:
warn "error while fetching peers from peer exchange", error = error
await sleepAsync(1.minutes)

proc startPeerExchangeLoop*(node: WakuNode) =
if node.wakuPeerExchange.isNil():
Expand Down Expand Up @@ -1252,6 +1254,10 @@ proc mountLibp2pPing*(node: WakuNode) {.async: (raises: []).} =
# TODO: Move this logic to PeerManager
proc keepaliveLoop(node: WakuNode, keepalive: chronos.Duration) {.async.} =
while true:
await sleepAsync(keepalive)
if not node.started:
continue

# Keep connected peers alive while running
# Each node is responsible of keeping its outgoing connections alive
trace "Running keepalive"
Expand All @@ -1269,8 +1275,6 @@ proc keepaliveLoop(node: WakuNode, keepalive: chronos.Duration) {.async.} =
except CatchableError as exc:
waku_node_errors.inc(labelValues = ["keep_alive_failure"])

await sleepAsync(keepalive)

proc startKeepalive*(node: WakuNode) =
let defaultKeepalive = 2.minutes # 20% of the default chronosstream timeout duration

Expand Down

0 comments on commit 3a72eb0

Please sign in to comment.