[JAVA-2811] Should not send lsid to a standalone Created: 14/Mar/18  Updated: 28/Oct/23  Resolved: 03/May/18

Status: Closed
Project: Java Driver
Component/s: Session Management
Affects Version/s: None
Fix Version/s: 3.8.0

Type: Bug Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CDRIVER-3070 Do not include lsid in commands if to... Closed

 Description   

The driver supports explicit and implicit sessions when connected to standalone servers, which goes against the spec, which says:

Standalone servers do not support sessions.

A driver can determine whether a replica set or sharded cluster deployment supports sessions by checking whether the logicalSessionTimeoutMinutes property of the TopologyDescription has a value or not. If it has a value the deployment supports sessions.

The check for whether a server supports sessions should exclude servers of type standalone.



 Comments   
Comment by Jeffrey Yemin [ 17/Oct/19 ]

thergfire@gmail.com, you are incorrect that standalone servers support transactions.  Note what happens when you try to do work in the transaction:

MongoDB Enterprise > session = db.getMongo().startSession()
session { "id" : UUID("5ecc9247-ecc4-4ee8-ac45-38a4d19d2ed6") }
MongoDB Enterprise > session.startTransaction()
MongoDB Enterprise > session.getDatabase("test").getCollection("test").insertOne({})
2019-10-17T08:11:12.060-0400 E  QUERY    [js] uncaught exception: WriteCommandError({
	"ok" : 0,
	"errmsg" : "Transaction numbers are only allowed on a replica set member or mongos",
	"code" : 20,
	"codeName" : "IllegalOperation"
}) :
WriteCommandError({
	"ok" : 0,
	"errmsg" : "Transaction numbers are only allowed on a replica set member or mongos",
	"code" : 20,
	"codeName" : "IllegalOperation"
})

For local development ease, I believe you can create a single member replica set, and that will support transactions.

 

Comment by Nikolay Firov [ 17/Oct/19 ]

Transactions requires sessions, and standalone server supports them:

$ mongo
MongoDB shell version v4.0.3
connecting to: mongodb://127.0.0.1:27017
{{Implicit session: session { "id" : UUID("a1329475-236c-4a2d-bde6-9118cf717c85") }}}
MongoDB server version: 4.2.0
....

> session = db.getMongo().startSession()
{{session { "id" : UUID("7327964d-13d1-4d3f-bc63-2ac031c4f032") }}}
> session.startTransaction()

> session.commitTransaction()

 

Why did you disable them in client? It makes harder to test code on local machine.

Comment by Githook User [ 03/May/18 ]

Author:

{'email': 'jeff.yemin@10gen.com', 'name': 'Jeff Yemin', 'username': 'jyemin'}

Message: JAVA-2811: Stop supporting client sessions for standalone servers

The driver sessions specification requires that client sessions not
be supported when connected to a MongoDB standalone server. This patch
ensures that explicitly created client sessions are not supported, and
that implicit sessions are not used, when connected to a standalone
server.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/2da2536157d5f9b7f3dc07812b82a52bbe95cce3

Generated at Thu Feb 08 08:58:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.