Skip to content

Commit c28608b

Browse files
W-A-Jamesnbbeeken
authored andcommitted
feat(NODE-6446): deprecate legacy timeout options (#4279)
Co-authored-by: Neal Beeken <neal.beeken@mongodb.com>
1 parent 55e08e7 commit c28608b

16 files changed

+140
-52
lines changed

src/connection_string.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,7 @@ export const OPTIONS = {
10921092
type: 'string'
10931093
},
10941094
socketTimeoutMS: {
1095+
deprecated: 'Please use timeoutMS instead',
10951096
default: 0,
10961097
type: 'uint'
10971098
},
@@ -1162,6 +1163,7 @@ export const OPTIONS = {
11621163
}
11631164
},
11641165
waitQueueTimeoutMS: {
1166+
deprecated: 'Please use timeoutMS instead',
11651167
default: 0,
11661168
type: 'uint'
11671169
},

src/cursor/abstract_cursor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export interface AbstractCursorOptions extends BSONSerializeOptions {
8484
/**
8585
* When applicable `maxTimeMS` controls the amount of time the initial command
8686
* that constructs a cursor should take. (ex. find, aggregate, listCollections)
87+
* @deprecated Will be removed in the next major version. Please use timeoutMS instead.
8788
*/
8889
maxTimeMS?: number;
8990
/**
@@ -721,6 +722,7 @@ export abstract class AbstractCursor<
721722
* Set a maxTimeMS on the cursor query, allowing for hard timeout limits on queries (Only supported on MongoDB 2.6 or higher)
722723
*
723724
* @param value - Number of milliseconds to wait before aborting the query.
725+
* @deprecated Will be removed in the next major version. Please use the timeoutMS option instead.
724726
*/
725727
maxTimeMS(value: number): this {
726728
this.throwIfInitialized();

src/cursor/aggregation_cursor.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ export class AggregationCursor<TSchema = any> extends ExplainableCursor<TSchema>
7575
...this.cursorOptions,
7676
session
7777
};
78-
try {
79-
validateExplainTimeoutOptions(options, Explain.fromOptions(options));
80-
} catch {
81-
throw new MongoAPIError(
82-
'timeoutMS cannot be used with explain when explain is specified in aggregateOptions'
83-
);
78+
if (options.explain) {
79+
try {
80+
validateExplainTimeoutOptions(options, Explain.fromOptions(options));
81+
} catch {
82+
throw new MongoAPIError(
83+
'timeoutMS cannot be used with explain when explain is specified in aggregateOptions'
84+
);
85+
}
8486
}
8587

8688
const aggregateOperation = new AggregateOperation(this.namespace, this.pipeline, options);

src/cursor/find_cursor.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ export class FindCursor<TSchema = any> extends ExplainableCursor<TSchema> {
7575
session
7676
};
7777

78-
try {
79-
validateExplainTimeoutOptions(options, Explain.fromOptions(options));
80-
} catch {
81-
throw new MongoAPIError(
82-
'timeoutMS cannot be used with explain when explain is specified in findOptions'
83-
);
78+
if (options.explain) {
79+
try {
80+
validateExplainTimeoutOptions(options, Explain.fromOptions(options));
81+
} catch {
82+
throw new MongoAPIError(
83+
'timeoutMS cannot be used with explain when explain is specified in findOptions'
84+
);
85+
}
8486
}
8587

8688
const findOperation = new FindOperation(this.namespace, this.cursorFilter, options);

src/cursor/run_command_cursor.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class RunCommandCursor extends AbstractCursor {
4848
/**
4949
* Controls the `getMore.maxTimeMS` field. Only valid when cursor is tailable await
5050
* @param maxTimeMS - the number of milliseconds to wait for new data
51+
* @deprecated Will be removed in the next major version. Please use timeoutMS instead.
5152
*/
5253
public setMaxTimeMS(maxTimeMS: number): this {
5354
this.getMoreOptions.maxAwaitTimeMS = maxTimeMS;
@@ -56,7 +57,7 @@ export class RunCommandCursor extends AbstractCursor {
5657

5758
/**
5859
* Controls the `getMore.batchSize` field
59-
* @param maxTimeMS - the number documents to return in the `nextBatch`
60+
* @param batchSize - the number documents to return in the `nextBatch`
6061
*/
6162
public setBatchSize(batchSize: number): this {
6263
this.getMoreOptions.batchSize = batchSize;
@@ -82,7 +83,10 @@ export class RunCommandCursor extends AbstractCursor {
8283
);
8384
}
8485

85-
/** Unsupported for RunCommandCursor: maxTimeMS must be configured directly on command document */
86+
/**
87+
* Unsupported for RunCommandCursor: maxTimeMS must be configured directly on command document
88+
* @deprecated Will be removed in the next major version.
89+
*/
8690
public override maxTimeMS(_: number): never {
8791
throw new MongoAPIError(
8892
'maxTimeMS must be configured on the command document directly, to configure getMore.maxTimeMS use cursor.setMaxTimeMS()'

src/mongo_client.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
152152
tlsInsecure?: boolean;
153153
/** The time in milliseconds to attempt a connection before timing out. */
154154
connectTimeoutMS?: number;
155-
/** The time in milliseconds to attempt a send or receive on a socket before the attempt times out. */
155+
/**
156+
* The time in milliseconds to attempt a send or receive on a socket before the attempt times out.
157+
* @deprecated Will be removed in the next major version. Please use timeoutMS instead
158+
*/
156159
socketTimeoutMS?: number;
157160
/** An array or comma-delimited string of compressors to enable network compression for communication between this client and a mongod/mongos instance. */
158161
compressors?: CompressorName[] | string;
@@ -176,7 +179,10 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
176179
maxConnecting?: number;
177180
/** The maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed. */
178181
maxIdleTimeMS?: number;
179-
/** The maximum time in milliseconds that a thread can wait for a connection to become available. */
182+
/**
183+
* The maximum time in milliseconds that a thread can wait for a connection to become available.
184+
* @deprecated Will be removed in the next major version. Please use timeoutMS instead
185+
*/
180186
waitQueueTimeoutMS?: number;
181187
/** Specify a read concern for the collection (only MongoDB 3.2 or higher supported) */
182188
readConcern?: ReadConcernLike;

src/operations/aggregate.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ export interface AggregateOptions extends Omit<CommandOperationOptions, 'explain
2626
bypassDocumentValidation?: boolean;
2727
/** Return the query as cursor, on 2.6 \> it returns as a real cursor on pre 2.6 it returns as an emulated cursor. */
2828
cursor?: Document;
29-
/** specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point. */
29+
/**
30+
* Specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point.
31+
* @deprecated Will be removed in the next major version. Please use timeoutMS instead.
32+
*/
3033
maxTimeMS?: number;
3134
/** The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. */
3235
maxAwaitTimeMS?: number;

src/operations/command.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export interface CommandOperationOptions
4040
readConcern?: ReadConcernLike;
4141
/** Collation */
4242
collation?: CollationOptions;
43+
/**
44+
* maxTimeMS is a server-side time limit in milliseconds for processing an operation.
45+
* @deprecated Will be removed in the next major version. Please use timeoutMS instead.
46+
*/
4347
maxTimeMS?: number;
4448
/**
4549
* Comment to apply to the operation.
@@ -97,7 +101,7 @@ export abstract class CommandOperation<T> extends AbstractOperation<T> {
97101

98102
if (this.hasAspect(Aspect.EXPLAINABLE)) {
99103
this.explain = Explain.fromOptions(options);
100-
validateExplainTimeoutOptions(this.options, this.explain);
104+
if (this.explain) validateExplainTimeoutOptions(this.options, this.explain);
101105
} else if (options?.explain != null) {
102106
throw new MongoInvalidArgumentError(`Option "explain" is not supported on this command`);
103107
}

src/operations/count.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export interface CountOptions extends CommandOperationOptions {
1313
skip?: number;
1414
/** The maximum amounts to count before aborting. */
1515
limit?: number;
16-
/** Number of milliseconds to wait before aborting the query. */
16+
/**
17+
* Number of milliseconds to wait before aborting the query.
18+
* @deprecated Will be removed in the next major version. Please use timeoutMS instead.
19+
*/
1720
maxTimeMS?: number;
1821
/** An index name hint for the query. */
1922
hint?: string | Document;

src/operations/estimated_document_count.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface EstimatedDocumentCountOptions extends CommandOperationOptions {
1212
* The maximum amount of time to allow the operation to run.
1313
*
1414
* This option is sent only if the caller explicitly provides a value. The default is to not send a value.
15+
* @deprecated Will be removed in the next major version. Please use timeoutMS instead.
1516
*/
1617
maxTimeMS?: number;
1718
}

0 commit comments

Comments
 (0)