From 4737892ccff154e7e7b4618d35e402a7984af202 Mon Sep 17 00:00:00 2001 From: Michele Bologna Date: Sat, 25 Apr 2026 13:50:16 +0200 Subject: [PATCH] fix: retry on first connection failure and on failed IRC registration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause: the socketClose reconnect gate checks reconnect_attempts > 0 && reconnect_attempts < max_retries But reconnect_attempts is initialised to 0, so the first connection failure always falls through to "give up" — the condition is falsy. Additionally, reconnect_attempts is reset in socketOpen (raw TCP connect), not in registeredSuccessfully. A connection that got a TCP socket but failed IRC registration (auth timeout, ECONNRESET during registration, server-side kill) would reset the counter immediately on the next attempt, exhausting retries before IRC registration ever succeeds. Fix (proposed by mornfall in #211, validated with ~100 users for 2+ years without issues): 1. Initialise reconnect_attempts to 1 so the first failure triggers the retry branch. 2. Remove the premature reset from socketOpen (TCP connected ≠ IRC registered). 3. Reset reconnect_attempts to 1 in registeredSuccessfully so the counter starts fresh after a fully successful registration. Fixes #211 --- src/connection.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/connection.js b/src/connection.js index d348b54d..2fe33d9b 100644 --- a/src/connection.js +++ b/src/connection.js @@ -15,7 +15,7 @@ module.exports = class Connection extends EventEmitter { this.connected = false; this.requested_disconnect = false; - this.reconnect_attempts = 0; + this.reconnect_attempts = 1; // When an IRC connection was successfully registered. this.registered = false; @@ -31,6 +31,7 @@ module.exports = class Connection extends EventEmitter { registeredSuccessfully() { this.registered = Date.now(); + this.reconnect_attempts = 1; } connect(options) { @@ -83,7 +84,6 @@ module.exports = class Connection extends EventEmitter { // Called when the socket is connected and ready to start sending/receiving data. function socketOpen() { that.debugOut('Socket fully connected'); - that.reconnect_attempts = 0; that.connected = true; that.emit('socket connected'); }