Announcement Announcement Module
Collapse
No announcement yet.
CannotGetMongoDbConnectionException in a multithreaded environment Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    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.

    Comment


    • #3
      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

      Comment


      • #4
        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.

        Comment


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

          Comment


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

            Comment

            Working...
            X