Skip to content

Conversation

@prestonvasquez
Copy link
Member

@prestonvasquez prestonvasquez commented Dec 18, 2025

DRIVERS-2782

Please complete the following before merging:

  • Is the relevant DRIVERS ticket in the PR title?

Go Driver POC: mongodb/mongo-go-driver#2271

  • Update changelog.
  • Test changes in at least one language driver.
  • Test these changes against all server versions and topologies (including standalone, replica set, and sharded
    clusters).

The Go Driver sets snapshotTime an experimental API:

type ClientSession{
  Snapshot *bson.Timestamp // Pointer reference
}

Users could easily update a session and use it in the pathological case

sess.ClientSession().Snapshot = &bson.Timestamp{T:1, I:1}
_ = sess.StartTransaction(options.Transaction().SetReadConcern(readconcern.New(
		readconcern.Level(readconcern.Snapshot().Level),
		
)))

_, _ = coll2.InsertOne(mongo.NewSessionContext(context.Background(), sess), bson.D{})

err = txnSes.CommitTransaction(context.Background())
// fails with: "(WriteConflict) Caused by ::  :: Please retry your operation or multi-document transaction."
// mongod logs show "Conflict with update with txn id [...] at timestamp: ([T2])"
require.NoError(t, err)

Drivers should ensure that snapshotTime is immutable, if it's already publicly readable. If it's not immutable, the behavior should be considered a bug.

@prestonvasquez prestonvasquez requested a review from a team as a code owner December 18, 2025 01:08
@prestonvasquez prestonvasquez requested review from papafe and sanych-sun and removed request for a team and sanych-sun December 18, 2025 01:08
Copy link
Contributor

@papafe papafe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@prestonvasquez prestonvasquez merged commit 0bc7fb6 into mongodb:master Dec 18, 2025
6 checks passed

**Approach 2: Immutability (if error-returning getters are not idiomatic)**

- Attempt to mutate the session's `snapshotTime` field through any publicly accessible API.
Copy link
Member

@sanych-sun sanych-sun Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this statement conflicts with requirement of immutability?

The snapshotTime field MUST be immutable
A readonly property called snapshotTime will be added to ClientSession that allows applications to retrieve the
snapshot time of the session:

Why would we have any public API to mutate the value? Or we are talking about a languages with no technical ability to make the field readonly?

- Start a session by calling `startSession` on with `snapshot = false`.
- Start a session by calling `startSession` with `snapshot = false`.

Drivers SHOULD implement one of the following approaches:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can say this is not a 2 approaches, this is simply 2 requirements:

  1. snapshot time should throw if snapshot = false (or return some special "Invalid" value if throwing is not an option).
  2. snapshot MUST be immutable.

prestonvasquez added a commit to prestonvasquez/specifications that referenced this pull request Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants