Ambiguity in docs - Transactions re-using the same ClientSession

Hi,
I have a question about transactions.

Imagine the following scenario:
We have a “Car”, with 4 "Wheel"s. These are stored in different collections and the Wheel object has a CarId property.
We also have the Archived property on all entities.
When we are archiving our Car, we are also cascading down to its Wheels and archiving them aswell.
This is done by having a custom MongoDbAdapter where T is either Car or Wheel.

The documentation states: “Use an IClientSession only with the MongoClient (or associated MongoDatabase or MongoCollection) that created it. Using an IClientSession with a different MongoClient results in operation errors.”

We have made a “transaction wrapper” with a Scoped lifetime which creates a new IClientSession if it does not exist, and reuses the existing if it already exists.
Then on the root level (our Car in this case), we are calling StartTransaction, CommitTransaction etc (with the MongoClient that created the ClientSession).
On our Wheels, none of the session methods get called - but we do send the ClientSession through to our operation, e.g. “UpdateOne(session, filter, entity)”.

We are unsure about the warning in the documentation - is it faulty to send the ClientSession through as we’re doing?
We could likely end up in a scenario where we send the session created by MongoClient_1 to an operation made by MongoClient_2 - and this seems to be working according to our tests.
Is it okay to send a session created by another client down to an operation? Or what potential problems could we face - or are we simply misunderstanding the Warning text in the documentation?

Kind regards,
Emil

Hi, Emil,

IClientSession instances can only be used by the MongoClient that created them. You use the IClientSession to coordinate work across multiple calls. This includes transactions, but also causally consistent reads (e.g. writing to the primary and reading the result from a secondary).

The recommended way to use this API is to start a session, start a transaction with that session, pass the session into any related operation (e.g. pass the same session to your Car and Wheel updates), and then commit the transaction. Either the Car and all Wheels are archived (e.g. commit succeeds) or none of them are (e.g. commit fails and an exception is thrown). You cannot end up in a situation where some are archived and others are not if you performed all the operations within a transaction using the same session. Hope that helps.

Sincerely,
James

Hi, thanks a lot for your response!
I understand all that and that’s the case we’re going to be in 99% of the time.
But we have also tried using a different MongoClient for Wheels and Cars - but using the same session in both of the clients - and it works.
I suspect that’s not supposed to be possible and we should not rely on that working going forwards?

Kind regards,
Emil