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
mongodbpackage!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,
timeoutMSthat 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
timeoutMSas 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?
timeoutMSThe main new option introduced with CSOT is the
timeoutMSoption. 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
timeoutMSoption is specified, it will always take precedence over the following options:socketTimeoutMSwaitQueueTimeoutMSwTimeoutMSmaxTimeMSmaxCommitTimeMSNote, however that
timeoutMSDOES NOT unconditionally override theserverSelectionTimeoutMSoption.When
timeoutMSis 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 forserverSelectionTimeoutMSof30000.After server selection and connection checkout are complete, the time remaining bounds the execution of the remainder of the operation.
Note
Specifying
timeoutMSis 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 * timeoutMSin'cursorLifetimeMode'and(n+1) * timeoutMSwhen returning n batches in'iteration'modeAbstractCursor.[Symbol.asyncIterator]()- can take up to2 * timeoutMSin'cursorLifetimeMode'and (n+1)*timeoutMSwhen 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.toArraycase 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 thekillCursorscommand to close the cursor on the server.The
MongoClient.bulkWriteand autoencryption implementations use cursors under the hood and so inherit this issue.Cursors,
timeoutMSandtimeoutModeCursors 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 thetimeoutMSto 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 subsequentgetMorecalls MUST finish withintimeoutMSor 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 akillCursorsoperation to the server.e.g.
The second,
'iteration'mode, usestimeoutMSto bound eachnext/hasNext/tryNextcall, 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
timeoutModeis also configurable on a per-cursor basis.GridFS and
timeoutMSGridFS streams interact with
timeoutMSin a similar manner to cursors in'cursorLifeTime'mode in thattimeoutMSbounds the entire lifetime of the stream.In addition,
GridFSBucket.find,GridFSBucket.renameandGridFSBucket.dropall support thetimeoutMSoption and behave in the same way as other operations.Sessions, Transactions,
timeoutMSanddefaultTimeoutMSClientSessions have a new option:
defaultTimeoutMS, which specifies thetimeoutMSvalue to use for:commitTransactionabortTransactionwithTransactionendSessionNote
If
defaultTimeoutMSis not specified, then it will inherit thetimeoutMSof the parentMongoClient.When using
ClientSession.withTransaction, thetimeoutMScan be configured either in the options on thewithTransactioncall or inherited from the session'sdefaultTimeoutMS. ThistimeoutMSwill apply to the entirety of thewithTransactioncallback 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 thetimeoutMSat the operation level for operations making use of the explicit session inside thewithTransactioncallback will result in an error being thrown.ClientEncryption and
timeoutMSThe
ClientEncryptionclass now supports thetimeoutMSoption. IftimeoutMSis provided when constructing aClientEncryptioninstance, it will be used to govern the lifetime of all operations performed on instance, otherwise, it will inherit from thetimeoutMSset on theMongoClientprovided to theClientEncryptionconstructor.If
timeoutMSis set on both the client and provided to ClientEncryption directly, the option provided toClientEncryptiontakes 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
MongoClientif 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
timeoutMSExplain helpers support timeoutMS:
Note
Providing a
maxTimeMSvalue with atimeoutMSvalue 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
ENVIRONMENTauth mechanism property in the URI orMongoClientoptions of "k8s".Example:
ConnectionClosedEvents always follow PoolClearedEvents
When Connection Monitoring and Pooling events are listened for,
ConnectionClosedEvents are now always emitted afterPoolClearEvents.Features
Bug Fixes
Performance Improvements
Documentation
We invite you to try the
mongodblibrary immediately, and report any issues to the NODE project.