@@ -143,16 +143,18 @@ proc areProtocolsSupported(
143143
144144proc 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
157159proc 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