Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: Handle MongoDB authentication issues #18993

Merged
merged 1 commit into from
Sep 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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