Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-15377

Mongo.getDatabaseNames() occasionally throws CommandFailureException - "exception: can't open database in a read lock."

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • ALL
    • Hide

      We see this periodically in our unit tests, where we have code that looks like:

      foreach (String dbName in mongo.getDatabaseNames()){
      mongo.getDatabase(dbName).drop();
      }

      Show
      We see this periodically in our unit tests, where we have code that looks like: foreach (String dbName in mongo.getDatabaseNames()){ mongo.getDatabase(dbName).drop(); }

      We have been having some problems where our mongo connection fails to allow us to get the database names from the DB.

      We call the method:

      com.mongodb.Mongo.getDatabaseNames()
      And 1 out of 100 times, it throws the following exception:

      Caused by: com.mongodb.CommandFailureException:

      { "serverUsed" : "localhost:27017" , "errmsg" : "exception: can't open database in a read lock. if db was just closed, consider retrying the query. might otherwise indicate an internal error" , "code" : 15927 , "ok" : 0.0}

      at com.mongodb.CommandResult.getException(CommandResult.java:76)
      at com.mongodb.CommandResult.throwOnError(CommandResult.java:131)
      at com.mongodb.Mongo.getDatabaseNames(Mongo.java:397)
      Looking at the mongo code, the database is the internal admin database

      public List<String> getDatabaseNames(){

      BasicDBObject cmd = new BasicDBObject();
      cmd.put("listDatabases", 1);

      >>CommandResult res = getDB(ADMIN_DATABASE_NAME).command(cmd, getOptions());
      res.throwOnError();
      This database is not being deleted, but there are several other databases that could be deleted around this time.

      Has anyone else had this problem?

      reposted from StackOverflow:
      http://stackoverflow.com/questions/25988180/mongo-getdatabasenames-occasionally-throws-commandfailureexception?noredirect=1#comment40757879_25988180

            Assignee:
            Unassigned Unassigned
            Reporter:
            greenkiwi Adam B
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: