chore(main): release 6.11.0 [skip-ci] #4317
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🌱 A new release!
6.11.0 (2024-11-22)
The MongoDB Node.js team is pleased to announce version 6.11.0 of the
mongodb
package!Release Notes
Client Side Operations Timeout (CSOT)
We've been working hard to try to simplify how setting timeouts works in the driver and are excited to finally put Client Side Operation Timeouts (CSOT) in your hands! We're looking forward to hearing your feedback on this new feature during its trial period in the driver, so feel free to file Improvements, Questions or Bug reports on our Jira Project or leave comments on this community forum thread: (link to be added shortly)!
CSOT is the common drivers solution for timing out the execution of an operation at the different stages of an operation's lifetime. At its simplest, CSOT allows you to specify one option,
timeoutMS
that determines when the driver will interrupt an operation and return a timeout error.For example, when executing a potentially long-running query, you would specify
timeoutMS
as follows:Warning
This feature is experimental and subject to change at any time. We do not recommend using this feature in production applications until it is stable.
What's new?
timeoutMS
The main new option introduced with CSOT is the
timeoutMS
option. This option can be applied directly as a client option, as well as at the database, collection, session, transaction and operation layers, following the same inheritance behaviours as other driver options.When the
timeoutMS
option is specified, it will always take precedence over the following options:socketTimeoutMS
waitQueueTimeoutMS
wTimeoutMS
maxTimeMS
maxCommitTimeMS
Note, however that
timeoutMS
DOES NOT unconditionally override theserverSelectionTimeoutMS
option.When
timeoutMS
is specified, the duration of time allotted to the server selection and connection checkout portions of command execution is defined bymin(serverSelectionTimeoutMS, timeoutMS)
if both are>0
. A zero value for either timeout value represents an infinite timeout. A finite timeout will always be used unless both timeouts are specified as0
. Note also that the driver has a default value forserverSelectionTimeoutMS
of30000
.After server selection and connection checkout are complete, the time remaining bounds the execution of the remainder of the operation.
Note
Specifying
timeoutMS
is not a hard guarantee that an operation will take exactly the duration specified. In the circumstances identified below, the driver's internal cleanup logic can result in an operation exceeding the duration specified bytimeoutMS
.AbstractCursor.toArray()
- can take up to2 * timeoutMS
in'cursorLifetimeMode'
and(n+1) * timeoutMS
when returning n batches in'iteration'
modeAbstractCursor.[Symbol.asyncIterator]()
- can take up to2 * timeoutMS
in'cursorLifetimeMode'
and (n+1)*timeoutMS
when returning n batches in'iteration'
modeMongoClient.bulkWrite()
- can take up to 2 * timeoutMS in error scenarios when the driver must clean up cursors used internally.In the
AbstractCursor.toArray
case and theAbstractCursor.[Symbol.asyncIterator]
case, this occurs as these methods close the cursor when they finish returning their documents. As detailed in the following section, this results in a refreshing of the timeout before sending thekillCursors
command to close the cursor on the server.The
MongoClient.bulkWrite
and autoencryption implementations use cursors under the hood and so inherit this issue.Cursors,
timeoutMS
andtimeoutMode
Cursors require special handling with the new timout paradigm introduced here. Cursors can be configured to interact with CSOT in two ways.
The first,
'cursorLifetime'
mode, uses thetimeoutMS
to bound the entire lifetime of a cursor and is the default timeout mode for non-tailable cursors (find, aggregate*, listCollections, etc.). This means that the initialization of the cursor and all subsequentgetMore
calls MUST finish withintimeoutMS
or a timeout error will be thrown. Note, however that the closing of a cursor, either as part of atoArray()
call or manually via theclose()
method resets the timeout before sending akillCursors
operation to the server.e.g.
The second,
'iteration'
mode, usestimeoutMS
to bound eachnext
/hasNext
/tryNext
call, refreshing the timeout after each call completes. This is the default mode for all tailable cursors (tailable find cursors on capped collections, change streams, etc.). e.g.Note that
timeoutMode
is also configurable on a per-cursor basis.GridFS and
timeoutMS
GridFS streams interact with
timeoutMS
in a similar manner to cursors in'cursorLifeTime'
mode in thattimeoutMS
bounds the entire lifetime of the stream.In addition,
GridFSBucket.find
,GridFSBucket.rename
andGridFSBucket.drop
all support thetimeoutMS
option and behave in the same way as other operations.Sessions, Transactions,
timeoutMS
anddefaultTimeoutMS
ClientSessions have a new option:
defaultTimeoutMS
, which specifies thetimeoutMS
value to use for:commitTransaction
abortTransaction
withTransaction
endSession
Note
If
defaultTimeoutMS
is not specified, then it will inherit thetimeoutMS
of the parentMongoClient
.When using
ClientSession.withTransaction
, thetimeoutMS
can be configured either in the options on thewithTransaction
call or inherited from the session'sdefaultTimeoutMS
. ThistimeoutMS
will apply to the entirety of thewithTransaction
callback provided that the session is correctly passed into each database operation. If the session is not passed into the operation, it will not respect the configured timeout. Also be aware that trying to override thetimeoutMS
at the operation level for operations making use of the explicit session inside thewithTransaction
callback will result in an error being thrown.ClientEncryption and
timeoutMS
The
ClientEncryption
class now supports thetimeoutMS
option. IftimeoutMS
is provided when constructing aClientEncryption
instance, it will be used to govern the lifetime of all operations performed on instance, otherwise, it will inherit from thetimeoutMS
set on theMongoClient
provided to theClientEncryption
constructor.If
timeoutMS
is set on both the client and provided to ClientEncryption directly, the option provided toClientEncryption
takes precedence.Limitations
At the time of writing, when using the driver's autoconnect feature alongside CSOT, the time taken for the command doing the autonnection will not be bound by the configured
timeoutMS
. We made this design choice because the client's connection logic handles a number of potentially long-running I/O and other setup operations including reading certificate files, DNS lookups, instantiating server monitors, and launching external processes for client encryption.We recommend manually connecting the
MongoClient
if intending to make use of CSOT, or otherwise ensuring that the driver is already connected when running commands that make use oftimeoutMS
.Explain helpers support
timeoutMS
Explain helpers support timeoutMS:
Note
Providing a
maxTimeMS
value with atimeoutMS
value will throw errors.MONGODB-OIDC Authentication now supports Kubernetes Environments.
For k8s environments running in Amazon's EKS (Elastic Kubernetes Service), Google's GKE (Google Kubernetes Engine), or Azure's AKS (Azure Kubernetes Service) simply provide an
ENVIRONMENT
auth mechanism property in the URI orMongoClient
options of "k8s".Example:
ConnectionClosedEvents always follow PoolClearedEvents
When Connection Monitoring and Pooling events are listened for,
ConnectionClosedEvent
s are now always emitted afterPoolClearEvent
s.Features
Bug Fixes
Performance Improvements
Documentation
We invite you to try the
mongodb
library immediately, and report any issues to the NODE project.