diff --git a/libp2p/utils/heartbeat.nim b/libp2p/utils/heartbeat.nim index 6756b1625..f0e7a5857 100644 --- a/libp2p/utils/heartbeat.nim +++ b/libp2p/utils/heartbeat.nim @@ -25,6 +25,14 @@ template heartbeat*(name: string, interval: Duration, body: untyped): untyped = nextHeartbeat += interval let now = Moment.now() if nextHeartbeat < now: - info "Missed heartbeat", heartbeat = name, delay = now - nextHeartbeat - nextHeartbeat = now + interval + let + delay = now - nextHeartbeat + itv = interval + if delay > itv: + info "Missed multiple heartbeats", heartbeat = name, + delay = delay, hinterval = itv + else: + debug "Missed heartbeat", heartbeat = name, + delay = delay, hinterval = itv + nextHeartbeat = now + itv await sleepAsync(nextHeartbeat - now)