Skip to content

Commit e5582ed

Browse files
nbbeekendariakp
authored andcommitted
docs(NODE-6516): add documentation for MongoOperationTimeoutError and fix internal references (#4315)
1 parent d29210e commit e5582ed

File tree

12 files changed

+28
-15
lines changed

12 files changed

+28
-15
lines changed

etc/notes/errors.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ This class should **never** be directly instantiated.
111111

112112
### `MongoOperationTimeoutError`
113113

114-
- TODO(NODE-6491): Add MongoOperationTimeoutError documentation
114+
The `MongoOperationTimeoutError` class represents an error that occurs when an operation could not be completed within the specified `timeoutMS`.
115+
It is generated by the driver in support of the "client side operation timeout" feature and inherits from `MongoDriverError`.
116+
When `timeoutMS` is enabled `MongoServerErrors` relating to `MaxTimeExpired` errors will be converted to `MongoOperationTimeoutError`.
115117

116118
### MongoUnexpectedServerResponseError
117119

src/client-side-encryption/auto_encrypter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export class AutoEncrypter {
312312
if (net.getDefaultAutoSelectFamily) {
313313
// AutoEncrypter is made inside of MongoClient constructor while options are being parsed,
314314
// we do not have access to the options that are in progress.
315-
// TODO(NODE-NODE-6449): AutoEncrypter does not use client options for autoSelectFamily
315+
// TODO(NODE-6449): AutoEncrypter does not use client options for autoSelectFamily
316316
Object.assign(clientOptions, autoSelectSocketOptions(this._client.s?.options ?? {}));
317317
}
318318

src/collection.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,8 @@ export class Collection<TSchema extends Document = Document> {
687687
);
688688
return true;
689689
} catch (error) {
690-
if (error instanceof MongoOperationTimeoutError) throw error; // TODO: Check the spec for index management behaviour/file a drivers ticket for this
691-
// Seems like we should throw all errors
690+
// TODO(NODE-6517): Driver should only filter for namespace not found error. Other errors should be thrown.
691+
if (error instanceof MongoOperationTimeoutError) throw error;
692692
return false;
693693
}
694694
}

src/error.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,9 @@ export class MongoUnexpectedServerResponseError extends MongoRuntimeError {
861861
* @public
862862
* @category Error
863863
*
864-
* This error is thrown when an operation could not be completed within the specified `timeoutMS`.
864+
* The `MongoOperationTimeoutError` class represents an error that occurs when an operation could not be completed within the specified `timeoutMS`.
865+
* It is generated by the driver in support of the "client side operation timeout" feature so inherits from `MongoDriverError`.
866+
* When `timeoutMS` is enabled `MongoServerError`s relating to `MaxTimeExpired` errors will be converted to `MongoOperationTimeoutError`
865867
*
866868
* @example
867869
* ```ts

src/gridfs/download.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export interface GridFSBucketReadStreamOptions {
3030
* to be returned by the stream. `end` is non-inclusive
3131
*/
3232
end?: number;
33-
/** @public */
33+
/**
34+
* @experimental
35+
* Specifies the time an operation will run until it throws a timeout error
36+
*/
3437
timeoutMS?: number;
3538
}
3639

src/gridfs/upload.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export interface GridFSBucketWriteStreamOptions extends WriteConcernOptions {
4242
* @deprecated Will be removed in the next major version. Add an aliases field to the metadata document instead.
4343
*/
4444
aliases?: string[];
45-
/** @public */
45+
/**
46+
* @experimental
47+
* Specifies the time an operation will run until it throws a timeout error
48+
*/
4649
timeoutMS?: number;
4750
}
4851

src/sdam/topology.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,10 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
460460
}
461461
}
462462

463-
// TODO(NODE-6223): auto connect cannot use timeoutMS
464-
// const timeoutMS = this.client.s.options.timeoutMS;
465463
const serverSelectionTimeoutMS = this.client.s.options.serverSelectionTimeoutMS;
466464
const readPreference = options.readPreference ?? ReadPreference.primary;
467465
const timeoutContext = TimeoutContext.create({
466+
// TODO(NODE-6448): auto-connect ignores timeoutMS; potential future feature
468467
timeoutMS: undefined,
469468
serverSelectionTimeoutMS,
470469
waitQueueTimeoutMS: this.client.s.options.waitQueueTimeoutMS

src/sessions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export interface ClientSessionOptions {
6161
defaultTransactionOptions?: TransactionOptions;
6262
/**
6363
* @public
64+
* @experimental
6465
* An overriding timeoutMS value to use for a client-side timeout.
6566
* If not provided the session uses the timeoutMS specified on the MongoClient.
6667
*/

test/integration/client-side-operations-timeout/client_side_operations_timeout.prose.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
import { type FailPoint, makeMultiBatchWrite, measureDuration } from '../../tools/utils';
2929
import { filterForCommands } from '../shared';
3030

31-
// TODO(NODE-5824): Implement CSOT prose tests
3231
describe('CSOT spec prose tests', function () {
3332
let internalClient: MongoClient;
3433
let client: MongoClient;

test/integration/client-side-operations-timeout/client_side_operations_timeout.spec.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const skippedTests = {
1616
'maxTimeMS value in the command is less than timeoutMS':
1717
'TODO(DRIVERS-2970): see modified test in unified-csot-node-specs',
1818
'timeoutMS is refreshed for getMore - failure':
19-
'TODO(DRIVERS-2965): see modified test in unified-csot-node-specs', // Skipping for both tailable awaitData and tailable non-awaitData cursors
19+
'TODO(DRIVERS-2965): see modified test in unified-csot-node-specs',
2020
'timeoutMS applies to full resume attempt in a next call': 'TODO(DRIVERS-3006)',
2121
'timeoutMS is refreshed for getMore if maxAwaitTimeMS is set': 'TODO(DRIVERS-3018)'
2222
};

test/integration/client-side-operations-timeout/client_side_operations_timeout.unit.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
import { measureDuration, sleep } from '../../tools/utils';
2626
import { createTimerSandbox } from '../../unit/timer_sandbox';
2727

28-
// TODO(NODE-5824): Implement CSOT prose tests
2928
describe('CSOT spec unit tests', function () {
3029
let client: MongoClient;
3130

@@ -107,7 +106,7 @@ describe('CSOT spec unit tests', function () {
107106
() => {}
108107
);
109108
}).skipReason =
110-
'TODO(NODE-5682): Add CSOT support for socket read/write at the connection layer for CRUD APIs';
109+
'TODO(NODE-6518): Add CSOT support for socket read/write at the connection layer for CRUD APIs';
111110

112111
describe('Client side encryption', function () {
113112
describe('KMS requests', function () {

test/unit/operations/get_more.test.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ describe('GetMoreOperation', function () {
5353
new ServerDescription('a:1'),
5454
{} as any
5555
);
56-
const opts = { ...options, documentsReturnedIn: 'nextBatch', returnFieldSelector: null };
56+
const opts = {
57+
...options,
58+
documentsReturnedIn: 'nextBatch',
59+
returnFieldSelector: null,
60+
timeoutContext: undefined
61+
};
5762
const operation = new GetMoreOperation(namespace, cursorId, server, opts);
5863
const stub = sinon.stub(server, 'command').resolves({});
5964

@@ -69,7 +74,7 @@ describe('GetMoreOperation', function () {
6974
const call = stub.getCall(0);
7075
expect(call.args[0]).to.equal(namespace);
7176
expect(call.args[1]).to.deep.equal(expectedGetMoreCommand);
72-
expect(call.args[2]).to.containSubset(opts);
77+
expect(call.args[2]).to.deep.equal(opts);
7378
});
7479
});
7580

0 commit comments

Comments
 (0)