com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=127.0.0.1:27017, type=Unknown, state=Connecting, exception={java.lang.NullPointerException}}]

JIRA | Jens Rommel | 2 years ago
  1. 0

    Using the Java driver 2.12.x against a mongoDB version 1.8 fails at startup due to com.mongodb.MongoTimeoutException caused by java.lang.NullPointerException (see stack trace below). The root cause seems to be the expected existence of "versionArray" in com.mongodb.ServerStateNotifier.getVersion(final CommandResult buildInfoResult) (v. 2.12.0, later moved to ServerMonitor.getVersion in 2.12.2) Apparently, mongoDB v1.8 doesn't provide the version as array. Is having a structured ServerVersion class really worth breaking backwards compatibility? Looks rather accidental to me. com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=127.0.0.1:27017, type=Unknown, state=Connecting, exception={java.lang.NullPointerException}}] at com.mongodb.BaseCluster.getDescription(BaseCluster.java:128) at com.mongodb.DBTCPConnector.getClusterDescription(DBTCPConnector.java:396) at com.mongodb.DBTCPConnector.getType(DBTCPConnector.java:569) at com.mongodb.DBTCPConnector.isMongosConnection(DBTCPConnector.java:370) at com.mongodb.Mongo.isMongosConnection(Mongo.java:645) at com.mongodb.DBCollection.findOne(DBCollection.java:865) at com.mongodb.DBCollection.findOne(DBCollection.java:843) at com.mongodb.DBCollection.findOne(DBCollection.java:789) at com.sap.sse.security.userstore.mongodb.impl.DomainObjectFactoryImpl.loadSettingTypes(DomainObjectFactoryImpl.java:199) at com.sap.sse.security.userstore.mongodb.UserStoreImpl.<init>(UserStoreImpl.java:55) at com.sap.sse.security.userstore.mongodb.impl.Activator.start(Activator.java:30) at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:771) at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1) at java.security.AccessController.doPrivileged(Native Method) at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:764) at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:721) at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:936) at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:319) at org.eclipse.osgi.container.Module.doStart(Module.java:571) at org.eclipse.osgi.container.Module.start(Module.java:439) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1582) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1562) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1533) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1476) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1) at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

    JIRA | 2 years ago | Jens Rommel
    com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=127.0.0.1:27017, type=Unknown, state=Connecting, exception={java.lang.NullPointerException}}]
  2. 0

    Using the Java driver 2.12.x against a mongoDB version 1.8 fails at startup due to com.mongodb.MongoTimeoutException caused by java.lang.NullPointerException (see stack trace below). The root cause seems to be the expected existence of "versionArray" in com.mongodb.ServerStateNotifier.getVersion(final CommandResult buildInfoResult) (v. 2.12.0, later moved to ServerMonitor.getVersion in 2.12.2) Apparently, mongoDB v1.8 doesn't provide the version as array. Is having a structured ServerVersion class really worth breaking backwards compatibility? Looks rather accidental to me. com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=127.0.0.1:27017, type=Unknown, state=Connecting, exception={java.lang.NullPointerException}}] at com.mongodb.BaseCluster.getDescription(BaseCluster.java:128) at com.mongodb.DBTCPConnector.getClusterDescription(DBTCPConnector.java:396) at com.mongodb.DBTCPConnector.getType(DBTCPConnector.java:569) at com.mongodb.DBTCPConnector.isMongosConnection(DBTCPConnector.java:370) at com.mongodb.Mongo.isMongosConnection(Mongo.java:645) at com.mongodb.DBCollection.findOne(DBCollection.java:865) at com.mongodb.DBCollection.findOne(DBCollection.java:843) at com.mongodb.DBCollection.findOne(DBCollection.java:789) at com.sap.sse.security.userstore.mongodb.impl.DomainObjectFactoryImpl.loadSettingTypes(DomainObjectFactoryImpl.java:199) at com.sap.sse.security.userstore.mongodb.UserStoreImpl.<init>(UserStoreImpl.java:55) at com.sap.sse.security.userstore.mongodb.impl.Activator.start(Activator.java:30) at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:771) at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1) at java.security.AccessController.doPrivileged(Native Method) at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:764) at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:721) at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:936) at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:319) at org.eclipse.osgi.container.Module.doStart(Module.java:571) at org.eclipse.osgi.container.Module.start(Module.java:439) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1582) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1562) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1533) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1476) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1) at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

    JIRA | 2 years ago | Jens Rommel
    com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=127.0.0.1:27017, type=Unknown, state=Connecting, exception={java.lang.NullPointerException}}]
  3. 0

    Inject mock services when testing a @RestController

    Stack Overflow | 11 months ago | mox601
    com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=localhost:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.ConnectException: Connection refused}}]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    If a 0 connection timeout is defined, it will causes an exception. {code:java} MongoClientOptions.Builder options = MongoClientOptions.builder(); options.connectTimeout(0); MongoClientURI mongoClientURI = new MongoClientURI("mongodb://127.0.0.1:27017", options); MongoClient mongoClient = new MongoClient(mongoClientURI); DB db = mongoClient.getDB("test"); DBCollection collection = db.getCollection("test"); System.out.println(collection.findOne()); {code} {noformat} Exception in thread "main" com.mongodb.MongoTimeoutException: Timed out after 0 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=localhost:27017, type=Unknown, state=Connecting}] at com.mongodb.BaseCluster.getDescription(BaseCluster.java:128) at com.mongodb.DBTCPConnector.getClusterDescription(DBTCPConnector.java:393) at com.mongodb.DBTCPConnector.getType(DBTCPConnector.java:565) at com.mongodb.DBTCPConnector.isMongosConnection(DBTCPConnector.java:367) at com.mongodb.Mongo.isMongosConnection(Mongo.java:645) at com.mongodb.DBCollection.findOne(DBCollection.java:865) at com.mongodb.DBCollection.findOne(DBCollection.java:843) at com.mongodb.DBCollection.findOne(DBCollection.java:789) at com.mongodb.DBCollection.findOne(DBCollection.java:778) at MongoTest.main(MongoTest.java:27) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) {noformat} That behaviour doesn't match the [driver documentation|http://api.mongodb.org/java/2.12/com/mongodb/MongoClientOptions.html#getConnectTimeout()]. I believe the following is one of the things on 2.12 that causes the behaviour because is obtaining the maximum wait time choosing the minimal value including the _connectTimeOut_. https://github.com/mongodb/mongo-java-driver/blob/r2.12.5/src/main/com/mongodb/DBTCPConnector.java#L396

    JIRA | 2 years ago | Ricardo Lorenzo
    com.mongodb.MongoTimeoutException: Timed out after 0 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=localhost:27017, type=Unknown, state=Connecting}]
  6. 0

    mongodb-user - [mongodb-user] Java driver cannot connect to MongoDB over SSL while MongoDB CLI can - msg#00522 - Recent Discussion OSDir.com

    osdir.com | 5 months ago
    com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=mon0101.pre2.zeldalabs.internal:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}]

  1. smyrgeorge 1 times, last 5 months ago
3 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. com.mongodb.MongoTimeoutException

    Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=127.0.0.1:27017, type=Unknown, state=Connecting, exception={java.lang.NullPointerException}}]

    at com.mongodb.BaseCluster.getDescription()
  2. MongoDB Java Driver
    DBCollection.findOne
    1. com.mongodb.BaseCluster.getDescription(BaseCluster.java:128)
    2. com.mongodb.DBTCPConnector.getClusterDescription(DBTCPConnector.java:396)
    3. com.mongodb.DBTCPConnector.getType(DBTCPConnector.java:569)
    4. com.mongodb.DBTCPConnector.isMongosConnection(DBTCPConnector.java:370)
    5. com.mongodb.Mongo.isMongosConnection(Mongo.java:645)
    6. com.mongodb.DBCollection.findOne(DBCollection.java:865)
    7. com.mongodb.DBCollection.findOne(DBCollection.java:843)
    8. com.mongodb.DBCollection.findOne(DBCollection.java:789)
    8 frames
  3. com.sap.sse
    Activator.start
    1. com.sap.sse.security.userstore.mongodb.impl.DomainObjectFactoryImpl.loadSettingTypes(DomainObjectFactoryImpl.java:199)
    2. com.sap.sse.security.userstore.mongodb.UserStoreImpl.<init>(UserStoreImpl.java:55)
    3. com.sap.sse.security.userstore.mongodb.impl.Activator.start(Activator.java:30)
    3 frames
  4. Eclipse OSGi
    BundleContextImpl$3.run
    1. org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:771)
    2. org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
    2 frames
  5. Java RT
    AccessController.doPrivileged
    1. java.security.AccessController.doPrivileged(Native Method)
    1 frame
  6. Eclipse OSGi
    EventManager$EventThread.run
    1. org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:764)
    2. org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:721)
    3. org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:936)
    4. org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:319)
    5. org.eclipse.osgi.container.Module.doStart(Module.java:571)
    6. org.eclipse.osgi.container.Module.start(Module.java:439)
    7. org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1582)
    8. org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1562)
    9. org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1533)
    10. org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1476)
    11. org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)
    12. org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    13. org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
    13 frames