Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-866

Not using read preference in all cases

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.0.0
    • Affects Version/s: 2.11.2
    • Component/s: Connection Management
    • Labels:
      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();
          }
        } 
      } 
      

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            rwallace@atlassian.com Richard Wallace
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: