From 917e3be21ea8c8a695089fceefbcb46501ff94de Mon Sep 17 00:00:00 2001 From: squankytoast Date: Sat, 25 Oct 2025 13:15:50 -0500 Subject: [PATCH 1/2] fix creation of duplicate periodic ping timers --- src/client.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/client.js b/src/client.js index 41dc30d6..78524445 100644 --- a/src/client.js +++ b/src/client.js @@ -339,10 +339,11 @@ module.exports = class IrcClient extends EventEmitter { startPeriodicPing() { const client = this; - let ping_timer = null; if (client.options.ping_interval <= 0) { return; + } else if (client.periodic_ping_timer) { + return; // do not create duplicate timer if already actively pinging the server } // Constantly ping the server for lag and time syncing functions @@ -351,8 +352,8 @@ module.exports = class IrcClient extends EventEmitter { } function resetPingTimer() { - client.connection.clearTimeout(ping_timer); - ping_timer = client.connection.setTimeout(pingServer, client.options.ping_interval * 1000); + client.connection.clearTimeout(client.periodic_ping_timer); + client.periodic_ping_timer = client.connection.setTimeout(pingServer, client.options.ping_interval * 1000); } // Browsers have started throttling looped timeout callbacks @@ -666,7 +667,11 @@ module.exports = class IrcClient extends EventEmitter { const commandName = 'ACTION'; const blockLength = this.options.message_max_length - (commandName.length + 3); - const blocks = [...lineBreak(message, { bytes: blockLength, allowBreakingWords: true, allowBreakingGraphemes: true })]; + const blocks = [...lineBreak(message, { + bytes: blockLength, + allowBreakingWords: true, + allowBreakingGraphemes: true + })]; blocks.forEach(function(block) { that.ctcpRequest(target, commandName, block); From a232261496c2e677b107c756d2a789680c6b5861 Mon Sep 17 00:00:00 2001 From: squankytoast Date: Sat, 25 Oct 2025 13:48:36 -0500 Subject: [PATCH 2/2] updating fix to include checking if the referenced ping timer is still alive --- src/client.js | 2 +- src/connection.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/client.js b/src/client.js index 78524445..c086d3cf 100644 --- a/src/client.js +++ b/src/client.js @@ -342,7 +342,7 @@ module.exports = class IrcClient extends EventEmitter { if (client.options.ping_interval <= 0) { return; - } else if (client.periodic_ping_timer) { + } else if (client.periodic_ping_timer && client.connection.hasTimeout(client.periodic_ping_timer)) { return; // do not create duplicate timer if already actively pinging the server } diff --git a/src/connection.js b/src/connection.js index d348b54d..d77c75b4 100644 --- a/src/connection.js +++ b/src/connection.js @@ -201,6 +201,10 @@ module.exports = class Connection extends EventEmitter { return tmr; } + hasTimeout(tmr) { + return (this._timers.includes(tmr)); + } + clearTimeout(tmr) { clearTimeout(tmr); _.pull(this._timers, tmr);