Skip to content

fix(data-service): skip compass ping during connect COMPASS-9455 #7083

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
38 changes: 1 addition & 37 deletions packages/data-service/src/connect-mongo-client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'assert';
import asyncHooks from 'async_hooks';
import { expect } from 'chai';
import type { MongoClientOptions, CommandStartedEvent } from 'mongodb';
import type { MongoClientOptions } from 'mongodb';

import {
connectMongoClientDataService as connectMongoClient,
Expand Down Expand Up @@ -170,42 +170,6 @@ describe('connectMongoClient', function () {
]);
});

it('should at least try to run a ping command to verify connectivity', async function () {
try {
await connectMongoClient({
connectionOptions: {
connectionString: 'mongodb://localhost:1/?loadBalanced=true',
},
setupListeners,
});
expect.fail('missed exception');
} catch (err: any) {
expect(err.name).to.equal('MongoNetworkError');
}
});

it('should not run the ping command with the specified ReadPreference', async function () {
const connectionString = clusterConnectionStringURL.clone();
connectionString
.typedSearchParams<MongoClientOptions>()
.set('readPreference', 'secondaryPreferred');
const commands: CommandStartedEvent[] = [];
const [metadataClient, crudClient, , state] = await connectMongoClient({
connectionOptions: {
connectionString: connectionString.toString(),
},
setupListeners: (client) =>
client.on('commandStarted', (ev) => commands.push(ev)),
});
expect(commands).to.have.lengthOf(1);
expect(commands[0].commandName).to.equal('ping');
expect(commands[0].command.$readPreference).to.equal(undefined);

for (const closeLater of [metadataClient, crudClient, state]) {
toBeClosed.add(closeLater);
}
});

describe('ssh tunnel failures', function () {
// Use async_hooks to track the state of the internal network server used
// for SSH tunneling
Expand Down
3 changes: 1 addition & 2 deletions packages/data-service/src/connect-mongo-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import _ from 'lodash';
import { redactConnectionOptions, redactConnectionString } from './redact';
import type { ConnectionOptions } from './connection-options';
import { getTunnelOptions, waitForTunnelError } from './ssh-tunnel-helpers';
import { runCommand } from './run-command';
import type { UnboundDataServiceImplLogger } from './logger';
import { debug as _debug } from './logger';

Expand Down Expand Up @@ -252,7 +251,7 @@ export async function connectMongoClientDataService({
connectLogger,
CompassMongoClient
);
await runCommand(client.db('admin'), { ping: 1 });

return {
client: Object.assign(client, {
async [createClonedClient]() {
Expand Down
Loading