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

Not using read preference in all cases

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 3.0.0
    • 2.11.2
    • Connection Management
    • None

    Description

      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();
          }
        } 
      } 

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: