Results 1 to 6 of 6

Thread: CannotGetMongoDbConnectionException in a multithreaded environment

  1. #1
    Join Date
    Nov 2011
    Posts
    5

    Default CannotGetMongoDbConnectionException in a multithreaded environment

    Hello,

    I am calling org.springframework.data.mongodb.core.MongoTemplat e.getCollection(String collectionName) from multiple threads and I get this exception quite often:

    Code:
    org.springframework.data.mongodb.CannotGetMongoDbConnectionException: Failed to authenticate to database [****], username = [****], password = [****]
    	at org.springframework.data.mongodb.core.MongoDbUtils.doGetDB(MongoDbUtils.java:100)
    	at org.springframework.data.mongodb.core.MongoDbUtils.getDB(MongoDbUtils.java:69)
    	at org.springframework.data.mongodb.core.SimpleMongoDbFactory.getDb(SimpleMongoDbFactory.java:98)
    	at org.springframework.data.mongodb.core.SimpleMongoDbFactory.getDb(SimpleMongoDbFactory.java:87)
    	at org.springframework.data.mongodb.core.MongoTemplate.getDb(MongoTemplate.java:964)
    	at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:312)
    	at org.springframework.data.mongodb.core.MongoTemplate.getCollection(MongoTemplate.java:365)
    Also in mongod log I observe the following message every time I get this exception:
    auth: bad nonce received or getnonce not called. could be a driver bug or a security attack

    Am I supposed to provide synchronization to this method from my own code? The documentation does not say it's not thread safe.

    Has anyone come across this issue?

    Also, I have made a sample program to reproduce this problem (attachment). Just import it to your favourite IDE, fill out the applicationContext.xml regarding the mongodb credentials and the collection name to query and finally launch the main method.

    Regs,
    Innar
    Attached Files Attached Files

  2. #2
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    Does that issue still persist if you use the driver natively? The log seems to suggest it's a driver issue and the relevant snippets in the code simply call db.authenticate(…). If you can still reproduce the issue it's probably reasonable to bring it to the MongoDB driver developer's table. Feel free to ping me back here as we are in contact with these guys and might be able to help raising the priority of the issue.

  3. #3
    Join Date
    Nov 2011
    Posts
    5

    Default

    Hello Oliver,

    Thanks for replying!

    I wrote another sample program that only uses the mongodb Java driver. I would say that we should investigate com.mongodb.DB.authenticate(...) thread safety. Depending where I call the authenticate method leads to different outcomes in the sample program (e.g same error in mongod logs).

    Please refer to the sample program attached. The default strategy succeeds, but if you switch to lazy authentication strategy you would start to experience errors.

    Regs,
    Innar
    Attached Files Attached Files

  4. #4
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    Would you mind filing this project in https://jira.mongodb.org? Removing the custom template code around the actual db.authenticate() might help getting the Mongo guys to look at it. Reduce the issue to the least amount of code possible. Please ping us back here so we can track progress with the Mongo guys.

  5. #5
    Join Date
    Nov 2011
    Posts
    5

    Default

    Yeah, I can do that, will post link here as a back-reference.

  6. #6
    Join Date
    Nov 2011
    Posts
    5

    Default

    Created an issue in mongodb jira, link https://jira.mongodb.org/browse/JAVA-582
    Last edited by innar.made; Jun 6th, 2012 at 10:13 AM. Reason: grammar

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •