Skip to content

Commit 4c6f76f

Browse files
authored
Merge branch 'master' into fix/capabilities_on_reconnect
2 parents c22356c + 1dd2a84 commit 4c6f76f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

changelog.d/115.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix reconnect loop due to the close listener being called on socket destruction.

src/irc.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,7 @@ 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+
this.unbindListeners();
12751276
this.conn.destroy();
12761277
this.conn = undefined;
12771278
}
@@ -1425,6 +1426,14 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
14251426
});
14261427
}
14271428

1429+
private unbindListeners() {
1430+
(
1431+
['data', 'end', 'close', 'timeout', 'error'] as (keyof IrcConnectionEventsMap)[]
1432+
).forEach(evtType => {
1433+
this.conn?.removeAllListeners(evtType);
1434+
});
1435+
}
1436+
14281437
private reconnect(retryCount: number) {
14291438
if (!this.isOurSocket) {
14301439
// Cannot reconnect if the socket is not ours.
@@ -1455,11 +1464,7 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
14551464
*/
14561465
public destroy() {
14571466
util.log('Destroying connection');
1458-
(
1459-
['data', 'end', 'close', 'timeout', 'error'] as (keyof IrcConnectionEventsMap)[]
1460-
).forEach(evtType => {
1461-
this.conn?.removeAllListeners(evtType);
1462-
});
1467+
this.unbindListeners();
14631468
if (this.isOurSocket) {
14641469
this.disconnect();
14651470
}

0 commit comments

Comments
 (0)