Skip to content

Commit 9e9059a

Browse files
feat(NODE-6377)!: remove noResponse option (#4724)
1 parent c38df51 commit 9e9059a

File tree

6 files changed

+35
-49
lines changed

6 files changed

+35
-49
lines changed

src/cmap/connection.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ export interface CommandOptions extends BSONSerializeOptions {
9090
/** Session to use for the operation */
9191
session?: ClientSession;
9292
documentsReturnedIn?: string;
93-
noResponse?: boolean;
9493
omitMaxTimeMS?: boolean;
9594

9695
// TODO(NODE-2802): Currently the CommandOptions take a property willRetryWrite which is a hint
@@ -467,7 +466,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
467466
signal: options.signal
468467
});
469468

470-
if (options.noResponse || message.moreToCome) {
469+
if (message.moreToCome) {
471470
yield MongoDBResponse.empty;
472471
return;
473472
}
@@ -567,11 +566,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
567566
new CommandSucceededEvent(
568567
this,
569568
message,
570-
options.noResponse
571-
? undefined
572-
: message.moreToCome
573-
? { ok: 1 }
574-
: (object ??= document.toObject(bsonOptions)),
569+
message.moreToCome ? { ok: 1 } : (object ??= document.toObject(bsonOptions)),
575570
started,
576571
this.description.serverConnectionId
577572
)

src/operations/command.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ export interface CommandOperationOptions
5656
// Admin command overrides.
5757
dbName?: string;
5858
authdb?: string;
59-
/**
60-
* @deprecated
61-
* This option is deprecated and will be removed in an upcoming major version.
62-
*/
63-
noResponse?: boolean;
6459

6560
/**
6661
* Used when the command needs to grant access to the underlying namespaces for time series collections.

src/operations/end_sessions.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ import {
33
type Connection,
44
type ServerCommandOptions,
55
type ServerSessionId,
6-
type TimeoutContext
6+
type TimeoutContext,
7+
type WriteConcern
78
} from '..';
89
import { type Document } from '../bson';
910
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
11+
import { CommandOperation } from '../operations/command';
1012
import { ReadPreference } from '../read_preference';
1113
import { MongoDBNamespace } from '../utils';
12-
import { AbstractOperation } from './operation';
14+
import { Aspect, defineAspects } from './operation';
1315

14-
export class EndSessionsOperation extends AbstractOperation<void> {
16+
export class EndSessionsOperation extends CommandOperation<void> {
17+
override writeConcern: WriteConcern = { w: 0 };
1518
override ns = MongoDBNamespace.fromString('admin.$cmd');
1619
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
1720

@@ -22,21 +25,20 @@ export class EndSessionsOperation extends AbstractOperation<void> {
2225
this.sessions = sessions;
2326
}
2427

25-
override buildCommand(_connection: Connection, _session?: ClientSession): Document {
28+
override buildCommandDocument(_connection: Connection, _session?: ClientSession): Document {
2629
return {
2730
endSessions: this.sessions
2831
};
2932
}
30-
3133
override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {
3234
return {
3335
timeoutContext,
34-
readPreference: ReadPreference.primaryPreferred,
35-
noResponse: true
36+
readPreference: ReadPreference.primaryPreferred
3637
};
3738
}
38-
3939
override get commandName(): string {
4040
return 'endSessions';
4141
}
4242
}
43+
44+
defineAspects(EndSessionsOperation, Aspect.WRITE_OPERATION);

test/integration/connection-monitoring-and-pooling/connection.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ describe('Connection', function () {
301301
req.reply({ ok: 1 });
302302
}, 800);
303303
})
304+
.addMessageHandler('endSessions', req => {
305+
// TODO(NODE-6287): remove support for QP_QUERY from the mock server
306+
// The mock server doesn't understand OP_MSG. So, MongoClient.close()'s use of the OP_MSG flag `moreToCome: true`
307+
// on endSessions isn't relevant, and this test hangs unless we have a handler for `endSessions`.
308+
// In practice, this isn't going to happen because we don't use OP_QUERY anywhere except for the initial
309+
// handshake.
310+
req.reply({ ok: 1 });
311+
})
304312
.addMessageHandler('hello', req => {
305313
req.reply(Object.assign({}, mock.HELLO));
306314
})

test/integration/node-specific/mongo_client.test.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as sinon from 'sinon';
55

66
import {
77
type Collection,
8-
type CommandFailedEvent,
98
type CommandStartedEvent,
109
type CommandSucceededEvent,
1110
Db,
@@ -862,23 +861,33 @@ describe('class MongoClient', function () {
862861
expect(result2).to.have.property('ok', 1);
863862
});
864863

865-
it('sends endSessions with noResponse set', async () => {
864+
it('sends endSessions with w: 0 set', async () => {
866865
const session = client.startSession(); // make a session to be ended
867866
await client.db('test').command({ ping: 1 }, { session });
868867
await session.endSession();
869868

870869
const startedEvents: CommandStartedEvent[] = [];
871-
const endEvents: Array<CommandFailedEvent | CommandSucceededEvent> = [];
870+
const endEvents: Array<CommandSucceededEvent> = [];
872871
client.on('commandStarted', event => startedEvents.push(event));
873872
client.on('commandSucceeded', event => endEvents.push(event));
874-
client.on('commandFailed', event => endEvents.push(event));
875873

876874
await client.close();
877875

878876
expect(startedEvents).to.have.lengthOf(1);
879-
expect(startedEvents[0]).to.have.property('commandName', 'endSessions');
877+
const [
878+
{
879+
command: { endSessions, writeConcern }
880+
}
881+
] = startedEvents;
882+
expect(endSessions).to.exist;
883+
expect(writeConcern).to.deep.equal({ w: 0 });
880884
expect(endEvents).to.have.lengthOf(1);
881-
expect(endEvents[0]).to.have.property('reply', undefined); // noReponse: true
885+
886+
const [{ reply }] = endEvents;
887+
888+
// when unacknowledged writes are used, the driver uses `{ ok: 1 }` as a placeholder
889+
// `reply` in CommandSucceededEvents
890+
expect(reply).to.deep.equal({ ok: 1 });
882891
});
883892

884893
describe('when server selection would return no servers', () => {

test/unit/cmap/connection.test.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,6 @@ describe('new Connection()', function () {
3535

3636
before(() => mock.createServer().then(s => (server = s)));
3737

38-
it('supports fire-and-forget messages', async function () {
39-
server.setMessageHandler(request => {
40-
const doc = request.document;
41-
if (isHello(doc)) {
42-
request.reply(mock.HELLO);
43-
}
44-
45-
// black hole all other requests
46-
});
47-
48-
const options = {
49-
...connectionOptionsDefaults,
50-
connectionType: Connection,
51-
hostAddress: server.hostAddress(),
52-
authProviders: new MongoClientAuthProviders()
53-
};
54-
55-
const conn = await connect(options);
56-
const readSpy = sinon.spy(conn, 'readMany');
57-
await conn.command(ns('$admin.cmd'), { ping: 1 }, { noResponse: true });
58-
expect(readSpy).to.not.have.been.called;
59-
});
60-
6138
it('destroys streams which time out', async function () {
6239
server.setMessageHandler(request => {
6340
const doc = request.document;

0 commit comments

Comments
 (0)