[JAVA-575] Driver re-auths on same connection Created: 27/May/12  Updated: 25/Jun/13  Resolved: 28/May/12

Status: Closed
Project: Java Driver
Component/s: Connection Management
Affects Version/s: 2.7.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jared D. Cottrell Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac OS X 10.7, 64-bit Mongo 2.0.4, Java 6



 Description   

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



 Comments   
Comment by Jeffrey Yemin [ 28/May/12 ]

I don't think this will cause any real performance impact in practice, as it's just one extra auth call.

Comment by Scott Hernandez (Inactive) [ 27/May/12 ]

There is one auth on the DB (unrelated to the port) which happens on the first call to authenticate, and then one for each port (which only happens once). This is by design and will only happen on the first port used the db.auth call. Are you seeing differently?

There may be some improvements to be made here but it might affect concurrency and be blocking while all the ports get the authentication cache updated.

Generated at Thu Feb 08 08:52:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.