0

Why the output stream receive errors immediately, while the exceptions in try-catch arrive after a long time (even after several minutes)?

I'm using Hibernate OGM which interfaces with a Mongo database. Can anyone tell me what is the problem? How to fix it or what should I study to understand it?

Specifically during login: when I try to access the database with the wrong parameters. Here the stream warns me that a com.mongodb.MongoCommandException has occurred. While application control is only returned to me after a com.mongodb.MongoTimeoutException.

Below, the System.out:

INFORMAZIONI: Exception in monitor thread while connecting to server <hidden>:27017
com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='daniele_cuomo', source='admin', password=<hidden>, mechanismProperties={}}
    at com.mongodb.connection.SaslAuthenticator.wrapInMongoSecurityException(SaslAuthenticator.java:157)
    at com.mongodb.connection.SaslAuthenticator.access$200(SaslAuthenticator.java:37)
    at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:66)
    at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:44)
    at com.mongodb.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:162)
    at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:44)
    at com.mongodb.connection.DefaultAuthenticator.authenticate(DefaultAuthenticator.java:32)
    at com.mongodb.connection.InternalStreamConnectionInitializer.authenticateAll(InternalStreamConnectionInitializer.java:109)
    at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:46)
    at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:116)
    at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server <hidden>:27017. The full response is { "ok" : 0.0, "code" : 18, "errmsg" : "Authentication failed." }
    at com.mongodb.connection.CommandHelper.createCommandFailureException(CommandHelper.java:170)
    at com.mongodb.connection.CommandHelper.receiveCommandResult(CommandHelper.java:123)
    at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:32)
    at com.mongodb.connection.SaslAuthenticator.sendSaslContinue(SaslAuthenticator.java:121)
    at com.mongodb.connection.SaslAuthenticator.access$100(SaslAuthenticator.java:37)
    at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:63)
Erwin Bolwidt
  • 30,799
  • 15
  • 56
  • 79
  • Can you add what the error is ? – dilsingi Jul 22 '17 at 15:33
  • That isn't a useful description, can you paste the complete error and is it possible to get the info from mongo system log? Also it looks like a timeout error and hence the wait till timeout period. Unless we get the full description, can't make sure why its timing out. – dilsingi Jul 22 '17 at 22:12

2 Answers2

0

com.mongodb.MongoTimeoutException go to this class and change the timeout period if it is available as open source library. also see what is the java api used here. ofcourse it wud depend on the jdk api used here.

0

You can set up the properties for the mongodb client using the following porperty:

hibernate.ogm.mongodb.driver.*

You can replace the * with any property from the MongoClientOption.Builder class, for example:

hibernate.ogm.mongodb.driver.connectTimeout

The official Hibernate OGM documentation contains all the details

Davide D'Alto
  • 7,421
  • 2
  • 16
  • 30
  • Thanks, I was already aware of this guide. However, I would like to configure the database so that when an error occurs I do not have to wait for a timeout. I would like to be aware of the error, I do not understand why there is a timeout, if I already know that the password is wrong (for example). –  Jul 24 '17 at 15:29
  • Additionally, add the following line to my dependencies.xml:        The application still makes me wait so much –  Jul 24 '17 at 15:35
  • This seems a problem in the configuration of the Client, not really Hibernate OGM. Hibernate OGM is simply creating a client using the mongo-java-driver library. If you can tell me what kind of configuration you want to pass I can check that everything is working as expected. – Davide D'Alto Jul 25 '17 at 11:38
  • I would like to handle the MongoCommandException rather than let do it to system, waiting for a (too generic) MongoTimeoutException. –  Jul 25 '17 at 13:42