Results 1 to 5 of 5

Thread: can't authenticate twice on same database

  1. #1
    Join Date
    Apr 2009
    Posts
    6

    Default can't authenticate twice on same database

    regarding mongodb

    Getting exception

    Code:
    java.lang.IllegalStateException: can't authenticate twice on the same database
    	at com.mongodb.DB.authenticate(DB.java:565)
    	at org.springframework.data.mongodb.core.MongoDbUtils.doGetDB(MongoDbUtils.java:113)
    	at org.springframework.data.mongodb.core.MongoDbUtils.getDB(MongoDbUtils.java:75)
    when trying to authenticate to auth enabled mongodb

    related xml
    Code:
    	<mongo:mongo id="mongodb" host="192.168.1.8" port="27017">
    	</mongo:mongo>
    
    	<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    	   <constructor-arg ref="mongodb"/>
    	   <constructor-arg name="databaseName" value="test-1"/>
    	  <constructor-arg name="userCredentials" ref="userCredentials"/>
    	</bean>
    	
    	<bean id="userCredentials" class="org.springframework.data.authentication.UserCredentials">
    	 	<constructor-arg name="username" value="usm"/>
    	  <constructor-arg name="password" value="pwd"/>
        </bean>
    application is multi-threaded, with multiple threads all inserting to mongodb at once. The first couple of threads succeed, insert their rows, and terminate.

    Am I doing this wrong, is this a bug?
    Last edited by kochcp; Nov 30th, 2012 at 08:24 AM.

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

    Default

    Which version of Spring Data MongoDB are you using?

  3. #3
    Join Date
    Apr 2009
    Posts
    6

    Default

    I have:

    spring-data-mongodb-1.1.0.RELEASE
    spring-data-cross-store-1.1.0.RELEASE
    spring-data-log4j-1.1.0.RELEASE

    spring-data-commons-core-1.4.0.RC1

    mongo driver 2.10.0

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

    Default

    It seems our synchonization range is too small as it doesn't include the !db.isAuthenticated() call, so two threads might run into the authentication block. Would you mind opening a ticket in our JIRA? I'm happy to include the fix in the next bug fix release then.

  5. #5
    Join Date
    Apr 2009
    Posts
    6

Posting Permissions

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