@@ -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 ()
@@ -275,8 +277,13 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
275277 let lp2pPeerStore = node.switch.peerStore
276278 let conStatus = node.peerManager.switch.peerStore[ConnectionBook ][peer.peerId]
277279
280+ var pingSuccess = true
278281 if conf.ping:
279- discard await pingFut
282+ try :
283+ pingSuccess = await pingFut
284+ except CatchableError :
285+ pingSuccess = false
286+ error " Ping operation failed or timed out"
280287
281288 if conStatus in [Connected , CanConnect ]:
282289 let nodeProtocols = lp2pPeerStore[ProtoBook ][peer.peerId]
@@ -285,6 +292,12 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
285292 error " Not all protocols are supported" ,
286293 expected = conf.protocols, supported = nodeProtocols
287294 quit (QuitFailure )
295+
296+ # Check ping result if ping was enabled
297+ if conf.ping and not pingSuccess:
298+ error " Node is reachable and supports protocols but ping failed - connection may be unstable"
299+ quit (QuitFailure )
300+
288301 elif conStatus == CannotConnect :
289302 error " Could not connect" , peerId = peer.peerId
290303 quit (QuitFailure )
0 commit comments