Skip to content

Commit

Permalink
Don't await connection when starting up in pooling mode (#1759)
Browse files Browse the repository at this point in the history
* Don't await connection for pooling mode

* changelog

* Fix log line
  • Loading branch information
Half-Shot authored Jul 31, 2023
1 parent 8bbd2b6 commit 9c37bd6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.d/1759.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a case where the bridge would not listen for and apply bans for legacy/unspec'd `m.room.rule.*` types in use by Mjolnir.
17 changes: 12 additions & 5 deletions src/bridge/IrcBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,13 +797,20 @@ export class IrcBridge {
}
);
memberlistPromises.push(
(async () => {
try {
await syncer.sync();
await discoveringClientsPromise;
}
catch (ex) {
log.warn(`Failed to handle memberlist sync`, ex);
}
finally {
await syncer.joinMatrixUsersToChannels()
}
})()
// Before we can actually join Matrix users to channels, we need to ensure we've discovered
// all the clients already connected to avoid races.
syncer.sync().then(() =>
discoveringClientsPromise
).finally(() =>
syncer.joinMatrixUsersToChannels()
)
);
});

Expand Down
11 changes: 8 additions & 3 deletions src/irc/ClientPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class ClientPool {
if (!this.redisPool) {
return;
}
log.info(`Discovering connected pool clients`);

// XXX: This is a safe assumption *for now* but when the proxy supports multiple
// servers this will break!
Expand All @@ -145,7 +146,8 @@ export class ClientPool {
// The bot will be connected via the usual process.
continue;
}
const mxUser = new MatrixUser(connection.clientId) ;
log.info(`Discovered ${connection.clientId}`);
const mxUser = new MatrixUser(connection.clientId);
if (this.getBridgedClientByUserId(server, mxUser.userId)) {
continue;
}
Expand All @@ -156,8 +158,11 @@ export class ClientPool {
mxUser, server.domain
);
const bridgeClient = await this.createIrcClient(config, mxUser, false, false);
await bridgeClient.connect();
log.info(`Connected previously connected user ${connection.clientId}`);
bridgeClient.connect().then(() => {
log.info(`Connected previously connected user ${connection.clientId}`);
}).catch((ex) => {
log.warn(`Failed to connect previously connected user ${connection.clientId}`, ex);
});
}
catch (ex) {
log.warn(`Failed to connect ${connection.clientId}, who is connected through the proxy`, ex);
Expand Down

0 comments on commit 9c37bd6

Please sign in to comment.