-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
Affects Version/s: 2.11.2
-
Component/s: Connection Management
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
In some cases the connection pinned to the request thread is used instead of the connection that should be. Specifically, if you do db.requestStart(), do a query with secondary preferred, then do a query with primary, the second query is run against the secondary and an error occurs. Example code
import com.mongodb._ class Test { public static void main(args: String[]) throws Exception { MongoClient m = new MongoClient(); DB db = m.getDB("test"); db.setReadPreference(ReadPreference.secondaryPreferred()); DBCollection c = db.getCollection("test"); db.requestStart(); try { c.findOne(); // works fine, pins request to secondary c.findOne(new BasicDBObject(), null, ReadPreference.primary()); // throws com.mongodb.MongoException: not talking to master and retries used up } finally { db.requestDone(); } } }