-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Session Management
-
None
-
Not Needed
Server sessions can be reused by the same database user who created them even across different connections and applications, but the Java driver validates that any session reference passed in is from the same MongoClient:
Exception: java.lang.IllegalStateException: state should be: ClientSession from same MongoClient
There are circumstances where 2 different connections are using the same MongoClient and using the same session. (We are using this case for integrity testing of some replica set operations involving IP resolution changes, where 1 mongoclient is connected to an old IP via a proxy, and 1 is connected to a new IP via a proxy).
I have tried to work around this validation by using runCommand() with an explicit `lsid` operation like so:
final Document result =
pClient
.getDatabase("test")
.runCommand(
new Document("find", "test")
.append("sort", new BsonDocument("i", new BsonInt32(1)))
}}{{.append("batchSize", 0)
}}{{.append("lsid", _sessionIdent));
But it appears in this case, the driver implicitly creates a new session and assigns a second `lsid` property, causing this server duplicate bson field error:
com.mongodb.MongoCommandException: Command failed with error 40413 (Location40413): 'BSON field 'APIParametersFromClient.lsid' is a duplicate field' on server xxx-hostname-here-xxx:27017. The full response is {"ok": 0.0, "errmsg": "BSON field 'APIParametersFromClient.lsid' is a duplicate field", "code": 40413, "codeName": "Location40413", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1615894777, "i": 1, "signature": {"hash":
{"$binary": "XQL3Tqirs9PAzLVPXsuKQHdxE4E=", "$type": "00"}, "keyId": {"$numberLong": "6939936267161305090"}}}, "operationTime": {"$timestamp":
{"t": 1615894777, "i": 1}}}}}
2 questions:
- Is there some way we can make use of a session ID created outside the MongoClient performing the operation, without driver code changes?
- It seems the server supports the operation, is the validation in question is superfluous and can it be removed?