Skip to content

Commit

Permalink
Fix reconnect loop
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jkhsjdhjs committed Jul 25, 2024
1 parent e53d6c9 commit fe0d2fe
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/irc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,12 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C

// destroy old socket before allocating a new one
if (this.isOurSocket && this.conn) {
// 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.
this.conn.removeAllListeners('close');
this.conn.destroy();
this.conn = undefined;
}
Expand Down

0 comments on commit fe0d2fe

Please sign in to comment.