Skip to content

Commit

Permalink
Merge pull request #979 from matrix-org/hs/fix-reconnections
Browse files Browse the repository at this point in the history
Fix reconnections
  • Loading branch information
Half-Shot authored Feb 13, 2020
2 parents 98a7323 + c11f8d7 commit 841d770
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
1 change: 1 addition & 0 deletions changelog.d/979.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix an issue where users were not rejoined to channels on netsplit/password change.
23 changes: 8 additions & 15 deletions src/irc/BridgedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> = new Set();
private connectDefer: promiseutil.Defer<void>;
public readonly log: LoggerInstance;
private cachedOperatorNicksInfo: {[channel: string]: GetNicksResponseOperators} = {};
Expand Down Expand Up @@ -143,7 +143,7 @@ export class BridgedClient extends EventEmitter {
}

public get chanList() {
return this._chanList;
return Array.from(this._chanList);
}

public get unsafeClient() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/irc/ClientPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 841d770

Please sign in to comment.