Skip to content

Commit

Permalink
Regression: Handle MongoDB authentication issues (RocketChat#18993)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok authored Sep 23, 2020
1 parent 707aa1f commit 0c276b5
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions app/models/server/models/_oplogHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,23 @@ class OplogHandle {
}

const { mongo } = MongoInternals.defaultRemoteCollectionDriver();
const { version, storageEngine } = await mongo.db.command({ serverStatus: 1 });
return storageEngine?.name === 'wiredTiger' && semver.satisfies(semver.coerce(version) || '', '>=3.6.0');

try {
const { version, storageEngine } = await mongo.db.command({ serverStatus: 1 });

if (!storageEngine || storageEngine.name !== 'wiredTiger' || !semver.satisfies(semver.coerce(version) || '', '>=3.6.0')) {
return false;
}

await mongo.db.admin().command({ replSetGetStatus: 1 });
} catch (e) {
if (e.message.startsWith('not authorized')) {
console.info('Change Stream is available for your installation, give admin permissions to your database user to use this improved version.');
}
return false;
}

return true;
}

async start(): Promise<OplogHandle> {
Expand All @@ -36,7 +51,7 @@ class OplogHandle {
try {
urlParsed = await urlParser(oplogUrl);
} catch (e) {
throw Error("$MONGO_OPLOG_URL must be set to the 'local' database of a Mongo replica set");
throw Error(`Error parsing database URL (${ oplogUrl })`);
}

if (!this.usingChangeStream && (!oplogUrl || urlParsed.dbName !== 'local')) {
Expand Down Expand Up @@ -164,9 +179,7 @@ let oplogHandle: Promise<OplogHandle>;
// @ts-ignore
// eslint-disable-next-line no-undef
if (Package['disable-oplog']) {
const { mongo } = MongoInternals.defaultRemoteCollectionDriver();
try {
Promise.await(mongo.db.admin().command({ replSetGetStatus: 1 }));
oplogHandle = Promise.await(new OplogHandle().start());
} catch (e) {
console.error(e.message);
Expand Down

0 comments on commit 0c276b5

Please sign in to comment.