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

Driver not catching "not master" error when running with replica pairs

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.1
    • Affects Version/s: 1.4, 2.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      mongodb server 1.4.3 - driver 2.0

      I've been trying to an application against a replica pair of mongodb 1.4.3 servers with driver version 2.0 (also occurs on 1.4). I've noticed an issue when servers switch master/slave roles that the driver is not transitioning and instead the error message filters up through the application. Here is a sample stack trace:

      com.mongodb.MongoException: error counting :

      { "" : "not master" , "ok" : 0.0}

      at com.mongodb.DBCollection.getCount(DBCollection.java:524)
      at com.mongodb.DBCollection.getCount(DBCollection.java:492)

      This error will occur if the master of the pair is taken down then brought back up without the application being aware of it. At that point, the current server in the driver would be pointing to the slave server. So, the next request from the driver would get "not master" error.

      After some investigation, I noticed that the problem appears to be in the way the error is caught. The driver expects errors to be in the format

      { "$err" : "....." }

      , however, in this case what I am seeing is

      { "errmsg" : "not master" }

      which doesn't get caught by Response.java as an error (so all the logic that is supposed to take place does not get triggered).

      I've locally made changes to also take "errmsg" as a valid error and then the switch between master/slave works. I've attached the two modified files for driver 2.0. I'm not certain why this error isn't coming up as "$err" - which would seem reasonable.

        1. Response.java
          5 kB
        2. ServerError.java
          1 kB

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            rloghin Razvan Loghin
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: