Skip to content

Commit c3c03b8

Browse files
MorganaFutureIvansete-status
authored andcommitted
fix: wakucanary now fails correctly when ping fails
1 parent cd5909f commit c3c03b8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

apps/wakucanary/wakucanary.nim

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,18 @@ proc areProtocolsSupported(
143143

144144
proc pingNode(
145145
node: WakuNode, peerInfo: RemotePeerInfo
146-
): Future[void] {.async, gcsafe.} =
146+
): Future[bool] {.async, gcsafe.} =
147147
try:
148148
let conn = await node.switch.dial(peerInfo.peerId, peerInfo.addrs, PingCodec)
149149
let pingDelay = await node.libp2pPing.ping(conn)
150150
info "Peer response time (ms)", peerId = peerInfo.peerId, ping = pingDelay.millis
151+
return true
151152
except CatchableError:
152153
var msg = getCurrentExceptionMsg()
153154
if msg == "Future operation cancelled!":
154155
msg = "timedout"
155156
error "Failed to ping the peer", peer = peerInfo, err = msg
157+
return false
156158

157159
proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
158160
let conf: WakuCanaryConf = WakuCanaryConf.load()
@@ -268,8 +270,13 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
268270
let lp2pPeerStore = node.switch.peerStore
269271
let conStatus = node.peerManager.switch.peerStore[ConnectionBook][peer.peerId]
270272

273+
var pingSuccess = true
271274
if conf.ping:
272-
discard await pingFut
275+
try:
276+
pingSuccess = await pingFut
277+
except CatchableError:
278+
pingSuccess = false
279+
error "Ping operation failed or timed out"
273280

274281
if conStatus in [Connected, CanConnect]:
275282
let nodeProtocols = lp2pPeerStore[ProtoBook][peer.peerId]
@@ -278,6 +285,12 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
278285
error "Not all protocols are supported",
279286
expected = conf.protocols, supported = nodeProtocols
280287
quit(QuitFailure)
288+
289+
# Check ping result if ping was enabled
290+
if conf.ping and not pingSuccess:
291+
error "Node is reachable and supports protocols but ping failed - connection may be unstable"
292+
quit(QuitFailure)
293+
281294
elif conStatus == CannotConnect:
282295
error "Could not connect", peerId = peer.peerId
283296
quit(QuitFailure)

0 commit comments

Comments
 (0)