-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(NODE-5233)!: prevent session from one client from being used on another #3790
Conversation
305a959
to
6ac44d4
Compare
6ac44d4
to
3e70911
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
questions from kickoff:
Did we decide referential equality was okay?
- best way to identify client? - instanceof is brittle, we can generate a unique id and/or use a symbol property; needs to account for legacy client usage
- what other identifier is there?
- what problems are there with checking referential equality?
Do we want to throw if a session from a LegacyMongoClient is passed into a MongoClient or vice versa?
Session prose test 5 says the following:
Repeat the above for all methods that take a session parameter.
Did we decide not to implement this and if so, should we add more APIs to the test? I don't think we need to exhaustively test the driver, but we should probably test more than a single insertOne
.
I see the following as tests in the kickoff but not in the PR:
- Unit test can check when sessions are and are not supported
- Check when a session is and is not from the client passed to executeOperation
I thought the plan was to unit test this in some way (specifically to unit test execute operation). Did the plan change?
src/operations/execute_operation.ts
Outdated
@@ -118,6 +118,8 @@ async function executeOperationAsync< | |||
throw new MongoExpiredSessionError('Use of expired sessions is not permitted'); | |||
} else if (session.snapshotEnabled && !topology.capabilities.supportsSnapshotReads) { | |||
throw new MongoCompatibilityError('Snapshot reads require MongoDB 5.0 or later'); | |||
} else if (session.client !== client) { | |||
throw new MongoRuntimeError('ClientSession must be from the same MongoClient'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a MongoInvalidArgument
error? We this error should be thrown when the user provides an invalid session as an argument.
From huddle:
|
Description
What is changing?
Is there new documentation needed for these changes?
API docs on startSession updated
What is the motivation for this change?
See highlights
Release Highlight
Driver methods throw if a session is provided from a different
MongoClient
Providing a session from one
MongoClient
to a method on a differentMongoClient
has never been a supported use case and leads to undefined behavior. To prevent this mistake, the driver now throws a if session is provided to a driver helper from a differentMongoClient
.Double check the following
npm run check:lint
scripttype(NODE-xxxx)[!]: description
feat(NODE-1234)!: rewriting everything in coffeescript