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=10.10.64.179:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused}}]

GitHub | pthewizard | 4 months ago
  1. 0

    Getting exception while connecting to mongodb using java code.

    GitHub | 4 months ago | pthewizard
    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=10.10.64.179:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused}}]
  2. 0
    You should init MongoClient only once.
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0
    If MongoDB is installed on the same instance as your app, use localhost to connect to MongoDB, e.g. 127.0.0.1:27017.
  5. 0

    java mongo连接问题,一直超时,原因不知道在哪

    oschina.net | 1 year 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=REPLICA_SET, servers=[{address=10.96.0.18:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=10.96.0.18:27018, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=10.96.0.7:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}]
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 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=10.10.64.179:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused}}]

    at com.mongodb.connection.BaseCluster.createTimeoutException()
  2. MongoDB Java Driver
    FindIterableImpl.first
    1. com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:375)
    2. com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:104)
    3. com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75)
    4. com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71)
    5. com.mongodb.binding.ClusterBinding.getReadConnectionSource(ClusterBinding.java:63)
    6. com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:212)
    7. com.mongodb.operation.FindOperation.execute(FindOperation.java:483)
    8. com.mongodb.operation.FindOperation.execute(FindOperation.java:80)
    9. com.mongodb.Mongo.execute(Mongo.java:818)
    10. com.mongodb.Mongo$2.execute(Mongo.java:805)
    11. com.mongodb.FindIterableImpl$FindOperationIterable.first(FindIterableImpl.java:207)
    12. com.mongodb.FindIterableImpl.first(FindIterableImpl.java:148)
    12 frames
  3. com.relevantcodes.extentreports
    Report.attach
    1. com.relevantcodes.extentreports.reporter.ExtentXReporter.setupProject(ExtentXReporter.java:195)
    2. com.relevantcodes.extentreports.reporter.ExtentXReporter.start(ExtentXReporter.java:161)
    3. com.relevantcodes.extentreports.Report.attach(Report.java:38)
    3 frames
  4. Java RT
    ReferencePipeline$Head.forEach
    1. java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
    2. java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
    2 frames
  5. com.relevantcodes.extentreports
    ExtentReports.attachReporter
    1. com.relevantcodes.extentreports.ExtentReports.attachReporter(ExtentReports.java:11)
    1 frame
  6. Unknown
    ExtentReport.beforeTest
    1. ExtentReport.beforeTest(ExtentReport.java:61)
    1 frame
  7. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    4. java.lang.reflect.Method.invoke(Method.java:498)
    4 frames
  8. TestNG
    RemoteTestNG.main
    1. org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
    2. org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
    3. org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
    4. org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
    5. org.testng.TestRunner.beforeRun(TestRunner.java:656)
    6. org.testng.TestRunner.run(TestRunner.java:624)
    7. org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    8. org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    9. org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    10. org.testng.SuiteRunner.run(SuiteRunner.java:268)
    11. org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    12. org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    13. org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    14. org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    15. org.testng.TestNG.run(TestNG.java:1064)
    16. org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
    17. org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152)
    18. org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)
    18 frames