From 6fcad7374e12121ed828f4cf9d026c80bbdafc60 Mon Sep 17 00:00:00 2001 From: jkhsjdhjs Date: Thu, 25 Jul 2024 01:38:41 +0200 Subject: [PATCH 1/4] Fix reconnect loop The 'close' listener is called when the socket is destroyed, which initiates another reconnect attempt. This reconnect attempt disconnects the new connection created by this control flow after the `retryDelay`. To avoid an endless reconnect loop, we need to remove the 'close' listener here before destroying the socket. Fix #96 --- src/irc.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/irc.ts b/src/irc.ts index 80eb972f..5cdda104 100644 --- a/src/irc.ts +++ b/src/irc.ts @@ -1272,6 +1272,12 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter Date: Sat, 27 Jul 2024 03:01:29 +0200 Subject: [PATCH 2/4] Add changelog.d entry Signed-off-by: jkhsjdhjs --- changelog.d/115.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/115.bugfix diff --git a/changelog.d/115.bugfix b/changelog.d/115.bugfix new file mode 100644 index 00000000..8aaddf77 --- /dev/null +++ b/changelog.d/115.bugfix @@ -0,0 +1 @@ +Fix reconnect loop due to the close listener being called on socket destruction From da58eb72b3d9698249683e8053b43f425ee926c1 Mon Sep 17 00:00:00 2001 From: jkhsjdhjs Date: Thu, 1 Aug 2024 14:24:27 +0200 Subject: [PATCH 3/4] Terminate changelog entry with a dot --- changelog.d/115.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/115.bugfix b/changelog.d/115.bugfix index 8aaddf77..ba0340a4 100644 --- a/changelog.d/115.bugfix +++ b/changelog.d/115.bugfix @@ -1 +1 @@ -Fix reconnect loop due to the close listener being called on socket destruction +Fix reconnect loop due to the close listener being called on socket destruction. From 5377bd5f687c7faf9a32ce4e4f5c1bf393062abb Mon Sep 17 00:00:00 2001 From: jkhsjdhjs Date: Thu, 1 Aug 2024 23:52:53 +0200 Subject: [PATCH 4/4] Unbind all listeners before socket destruction --- src/irc.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/irc.ts b/src/irc.ts index 5cdda104..a85769ac 100644 --- a/src/irc.ts +++ b/src/irc.ts @@ -1272,12 +1272,7 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter TypedEmitter { + this.conn?.removeAllListeners(evtType); + }); + } + private reconnect(retryCount: number) { if (!this.isOurSocket) { // Cannot reconnect if the socket is not ours. @@ -1461,11 +1464,7 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter { - this.conn?.removeAllListeners(evtType); - }); + this.unbindListeners(); if (this.isOurSocket) { this.disconnect(); }