node-mongodb-native icon indicating copy to clipboard operation
node-mongodb-native copied to clipboard

feat(CSOT) - feature branch

Open W-A-James opened this issue 10 months ago • 3 comments

Description

What is changing?

New Error
  • Added MongoOperationTimeoutError class that is thrown when a CSOT timeout is encountered
Changes to Timeout
  • Add Timeout.throwIfExpired() method
  • Add Timeout.remainingTime getter method
Updates to AbstractOperation
  • Add timeout field
    • timeout is set at construction if the timeoutMS option is provided
Implementing CSOT behaviour for server selection
  • Update Topology.selectServer to accept a timeout option which it will use determine whether it has timed out when defined. Otherwise, constructs a Timeout using the serverSelectionMS option as before
  • Update Topology.selectServer to throw a MongoOperationTimeoutError on timeout when options.timeout is provided and retain previous error behaviour otherwise.
  • Update Topology._connect to pass down timeout to Server.command call used to execute ping on first connection
Implementing CSOT behaviour for connection checkout
  • Update Server.command to accept timeout option.
  • Update ConnectionPool.checkOut to accept timeout option
    • only uses the passed in timeout if the configured serverSelectionTimeoutMS is greater than the duration on the timeout, otherwise, computes the time elapsed since server selection completed and creates timeout for the serverSelectionTimeoutMS deadline
Test changes
  • Implement Server Selection prose tests from CSOT spec. Left out last two since they require implementation of the connection creation cancellation behaviour that was decided against in DRIVERS-2347
  • Implement unit tests from CSOT spec related to server selection and connection checkout. Skipped tests with appropriate messages
Misc changes
  • Update resolveOptions to handle timeoutMS option propagation
    • Add csotMin helper method that implements the CSOT min algorithm described here
Is there new documentation needed for these changes?

What is the motivation for this change?

Release Highlight

Fill in title or leave empty for no highlight

Double check the following

  • [ ] Ran npm run check:lint script
  • [ ] Self-review completed using the steps outlined here
  • [ ] PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • [ ] Changes are covered by tests
  • [ ] New TODOs have a related JIRA ticket

W-A-James avatar Apr 23 '24 20:04 W-A-James

Evergreen link

W-A-James avatar May 03 '24 22:05 W-A-James

Bookkeeping: Waiting for Warren to respond to Bailey's comments and will proceed with review then.

aditi-khare-mongoDB avatar May 06 '24 17:05 aditi-khare-mongoDB

@aditi-khare-mongoDB @nbbeeken should we conditionally clear the timeout on success/a non-timeout failure based on whether or not we created the timeout inside the function that we race the timeout with? I ask because we don't always own Timeout instance we're using in Topology.selectServer or in ConnectionPool.checkOut.

W-A-James avatar May 07 '24 20:05 W-A-James