Skip to content

Commit fe0d2fe

Browse files
committed
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
1 parent e53d6c9 commit fe0d2fe

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/irc.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,12 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
12721272

12731273
// destroy old socket before allocating a new one
12741274
if (this.isOurSocket && this.conn) {
1275+
// The 'close' listener is called when the socket is destroyed, which
1276+
// initiates another reconnect attempt. This reconnect attempt disconnects
1277+
// the new connection created by this control flow after the `retryDelay`.
1278+
// To avoid an endless reconnect loop, we need to remove the 'close'
1279+
// listener here before destroying the socket.
1280+
this.conn.removeAllListeners('close');
12751281
this.conn.destroy();
12761282
this.conn = undefined;
12771283
}

0 commit comments

Comments
 (0)