From 6c272da89cd0ce5eec4d8f6a7b222417a4bb612d Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 13 Feb 2020 15:25:34 +0000 Subject: [PATCH 1/2] Ensure we rejoin channels on reconnect --- src/irc/BridgedClient.ts | 23 ++++++++--------------- src/irc/ClientPool.ts | 2 +- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/irc/BridgedClient.ts b/src/irc/BridgedClient.ts index f04ae78e1..d28dbd53a 100644 --- a/src/irc/BridgedClient.ts +++ b/src/irc/BridgedClient.ts @@ -62,7 +62,7 @@ export class BridgedClient extends EventEmitter { private instCreationFailed = false; private _explicitDisconnect = false; private _disconnectReason: string|null = null; - private _chanList: string[] = []; + private _chanList: Set = new Set(); private connectDefer: promiseutil.Defer; public readonly log: LoggerInstance; private cachedOperatorNicksInfo: {[channel: string]: GetNicksResponseOperators} = {}; @@ -143,7 +143,7 @@ export class BridgedClient extends EventEmitter { } public get chanList() { - return this._chanList; + return Array.from(this._chanList); } public get unsafeClient() { @@ -279,7 +279,8 @@ export class BridgedClient extends EventEmitter { } } - public async reconnect() { + public async reconnect(reconnectChanList: string[]) { + reconnectChanList.forEach((c) => this._chanList.add(c)); await this.connect(); this.log.info( "Reconnected %s@%s", this.nick, this.server.domain @@ -389,7 +390,7 @@ export class BridgedClient extends EventEmitter { } public inChannel(channel: string) { - return this.chanList.includes(channel); + return this._chanList.has(channel); } public kick(nick: string, channel: string, reason: string) { @@ -673,19 +674,11 @@ export class BridgedClient extends EventEmitter { } private removeChannel(channel: string) { - const i = this.chanList.indexOf(channel); - if (i === -1) { - return; - } - this.chanList.splice(i, 1); + this._chanList.delete(channel); } private addChannel(channel: string) { - const i = this.chanList.indexOf(channel); - if (i !== -1) { - return; // already added - } - this.chanList.push(channel); + this._chanList.add(channel); } public getLastActionTs() { @@ -828,7 +821,7 @@ export class BridgedClient extends EventEmitter { return; } // promise isn't resolved yet and we still want to join this channel - if (defer.promise.isPending() && this.chanList.indexOf(channel) !== -1) { + if (defer.promise.isPending() && this._chanList.has(channel)) { // we may have joined but didn't get the callback so check the client if (Object.keys(this.unsafeClient.chans).indexOf(channel) !== -1) { // we're joined diff --git a/src/irc/ClientPool.ts b/src/irc/ClientPool.ts index 743969700..4f0535fac 100644 --- a/src/irc/ClientPool.ts +++ b/src/irc/ClientPool.ts @@ -607,7 +607,7 @@ export class ClientPool { private async reconnectClient(cliChan: ReconnectionItem) { try { - await cliChan.cli.reconnect(); + await cliChan.cli.reconnect(cliChan.chanList); } catch (ex) { log.error( From c11f8d7cd582da75580d2627beb517601143a334 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 13 Feb 2020 15:29:26 +0000 Subject: [PATCH 2/2] changelog --- changelog.d/979.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/979.bugfix diff --git a/changelog.d/979.bugfix b/changelog.d/979.bugfix new file mode 100644 index 000000000..079beeecc --- /dev/null +++ b/changelog.d/979.bugfix @@ -0,0 +1 @@ +Fix an issue where users were not rejoined to channels on netsplit/password change. \ No newline at end of file