-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.13.1
-
Component/s: None
-
Labels:None
I found the following problem
// Mongo client with credentials on a non existing user // we expect an auth failure error MongoClient mongo = ...; try { // this will raise an auth failure exception mongo.getDatabaseNames().contains( databaseName ); } catch (MongoException me) { // auth failure exception, that's cool } try { // we try again to connect with the same credentials // we should get an auth failure db.collectionExists( "WeDoNotCareWhatItIsWeNeedToConnect" ); } catch (MongoException me) { if ( me.getCode() == 18 ) { //AUTHENTICATION_FAILED_CODE System.out.println("Auth failure"); } if ( me instanceof MongoTimeoutException ) { System.out.println("Timeout failure"); } }
This code without the thread sleep will raise a timeout exception. With the thread sleep (or with a debug/break point enforced), I get the expected auth failure.
Some kind of race condition is going on during the second connection attempt.
Retrying twice (i.e. on the third attempt to do db.collectionExists( "WeDoNotCareWhatItIsWeNeedToConnect" ); it works.
It might be related to JAVA-1780 but I don't know much about it. And trying the latest 2.13.2-SNAPSHOT did nto fix the issue