mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-02 14:03:06 +00:00
fix: wakucanary now fails correctly when ping fails (#3595)
* wakucanary add some more detail if exception Co-authored-by: MorganaFuture <andrewmochalskyi@gmail.com>
This commit is contained in:
parent
cd5909fafe
commit
adeb1a928e
@ -143,16 +143,18 @@ proc areProtocolsSupported(
|
||||
|
||||
proc pingNode(
|
||||
node: WakuNode, peerInfo: RemotePeerInfo
|
||||
): Future[void] {.async, gcsafe.} =
|
||||
): Future[bool] {.async, gcsafe.} =
|
||||
try:
|
||||
let conn = await node.switch.dial(peerInfo.peerId, peerInfo.addrs, PingCodec)
|
||||
let pingDelay = await node.libp2pPing.ping(conn)
|
||||
info "Peer response time (ms)", peerId = peerInfo.peerId, ping = pingDelay.millis
|
||||
return true
|
||||
except CatchableError:
|
||||
var msg = getCurrentExceptionMsg()
|
||||
if msg == "Future operation cancelled!":
|
||||
msg = "timedout"
|
||||
error "Failed to ping the peer", peer = peerInfo, err = msg
|
||||
return false
|
||||
|
||||
proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
|
||||
let conf: WakuCanaryConf = WakuCanaryConf.load()
|
||||
@ -268,8 +270,13 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
|
||||
let lp2pPeerStore = node.switch.peerStore
|
||||
let conStatus = node.peerManager.switch.peerStore[ConnectionBook][peer.peerId]
|
||||
|
||||
var pingSuccess = true
|
||||
if conf.ping:
|
||||
discard await pingFut
|
||||
try:
|
||||
pingSuccess = await pingFut
|
||||
except CatchableError as exc:
|
||||
pingSuccess = false
|
||||
error "Ping operation failed or timed out", error = exc.msg
|
||||
|
||||
if conStatus in [Connected, CanConnect]:
|
||||
let nodeProtocols = lp2pPeerStore[ProtoBook][peer.peerId]
|
||||
@ -278,6 +285,11 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
|
||||
error "Not all protocols are supported",
|
||||
expected = conf.protocols, supported = nodeProtocols
|
||||
quit(QuitFailure)
|
||||
|
||||
# Check ping result if ping was enabled
|
||||
if conf.ping and not pingSuccess:
|
||||
error "Node is reachable and supports protocols but ping failed - connection may be unstable"
|
||||
quit(QuitFailure)
|
||||
elif conStatus == CannotConnect:
|
||||
error "Could not connect", peerId = peer.peerId
|
||||
quit(QuitFailure)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user