diff --git a/packages/core/src/lib/keep_alive_manager.ts b/packages/core/src/lib/keep_alive_manager.ts index 26f7c296d9..9746f52869 100644 --- a/packages/core/src/lib/keep_alive_manager.ts +++ b/packages/core/src/lib/keep_alive_manager.ts @@ -37,14 +37,24 @@ export class KeepAliveManager { const peerIdStr = peerId.toString(); + // Ping the peer every pingPeriodSecs seconds + // if pingPeriodSecs is 0, don't ping the peer if (pingPeriodSecs !== 0) { const interval = setInterval(() => { void (async () => { + let ping: number; try { // ping the peer for keep alive // also update the peer store with the latency - const ping = await libp2pPing.ping(peerId); - log(`Ping succeeded (${peerIdStr})`, ping); + try { + ping = await libp2pPing.ping(peerId); + log(`Ping succeeded (${peerIdStr})`, ping); + } catch (error) { + log(`Ping failed for peer (${peerIdStr}). + Next ping will be attempted in ${pingPeriodSecs} seconds. + `); + return; + } try { await peerStore.patch(peerId, { diff --git a/packages/core/src/lib/waku.ts b/packages/core/src/lib/waku.ts index d4134ac07f..0da4102ab1 100644 --- a/packages/core/src/lib/waku.ts +++ b/packages/core/src/lib/waku.ts @@ -15,7 +15,7 @@ import debug from "debug"; import { ConnectionManager } from "./connection_manager.js"; -export const DefaultPingKeepAliveValueSecs = 0; +export const DefaultPingKeepAliveValueSecs = 5 * 60; export const DefaultRelayKeepAliveValueSecs = 5 * 60; export const DefaultUserAgent = "js-waku";