From aaba729dc2275a3cd9dc7576d9b2d7b57284f812 Mon Sep 17 00:00:00 2001 From: Sameer Kumar Subudhi Date: Mon, 8 Jan 2024 20:22:57 +0530 Subject: [PATCH] :bug: Fix logic api client healthcheck logic --- services/blockchain-connector/shared/sdk/client.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/blockchain-connector/shared/sdk/client.js b/services/blockchain-connector/shared/sdk/client.js index ff56665441..80589739d3 100644 --- a/services/blockchain-connector/shared/sdk/client.js +++ b/services/blockchain-connector/shared/sdk/client.js @@ -76,9 +76,9 @@ const pingListener = apiClient => { clearTimeout(apiClient.pingTimeout); apiClient.pingTimeout = setTimeout(() => { - // Do not reset if the ping was delayed and just received - const timeSinceLastPing = now - apiClient.lastPingAt; - if (timeSinceLastPing) { + // Inside this callback, `now` refers to the time when the previous ping was received and this instance of timeout was set + const timeSinceLastPing = Date.now() - now; + if (timeSinceLastPing - WS_SERVER_PING_THRESHOLD > 0) { logger.warn( `No ping for client ${apiClient.poolIndex} from server in ${timeSinceLastPing}ms (last ping: ${apiClient.lastPingAt}).`, );