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

Driver re-auths on same connection

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.7.3
    • Component/s: Connection Management
    • Labels:
      None
    • Environment:
      Mac OS X 10.7, 64-bit Mongo 2.0.4, Java 6

      We are seeing connections very commonly re-authenticate with the same credentials on the same connection. We've replicated the problem with the simple test driver below. Tracing through the code a bit, it looks like the DB auths first (in DB.authenticate() below) and then the DBPort does it again when it's finally used (in DBCursor.toArray() below).

      import com.mongodb.DB;
      import com.mongodb.MongoURI;
      
      public class AuthTest {
      
          public static final String MONGO_URI = "mongodb://username:password@localhost/database";
      
          public static void main ( String[] args ) {
              try {
                  MongoURI uri = new MongoURI(MONGO_URI);
                  DB db = uri.connectDB();
                  db.authenticate(uri.getUsername(), uri.getPassword());
                  db.getCollection("collection").find().toArray();
              } catch ( Exception e ) {
                  e.printStackTrace();
              }
          }
      
      }
      

      Here's an example from the mongodb.log that shows the re-auth from a run of the test driver.

      Sat May 26 18:53:27 [initandlisten] connection accepted from 192.168.1.90:56497 #63
      Sat May 26 18:53:27 [conn63]  authenticate: { authenticate: 1, user: "username", nonce: "a7ff424cc52c3fb9", key: "d520523babbc8fc133feec681409d77f" }
      Sat May 26 18:53:27 [conn63]  authenticate: { authenticate: 1, user: "username", nonce: "6b31c591ff203471", key: "cb243f059038af803511683c87b26e06" }
      Sat May 26 18:53:28 [conn63] end connection 192.168.1.90:56497
      

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            jared Jared D. Cottrell
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: