java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect

JIRA | Alan Williamson | 4 years ago
  1. 0

    The Java driver is great when everything goes right. However, the weakness can be seen when things start to go wrong. Let me illustrate with an example. A very simple one ... detecting when the server is available. You can't! Say for example you wanted to make sure the server was available (maybe you start your client before the server, or the server goes away for maintenance for a few moments (backup)). Take the following piece of code: try{ mongo.getConnector().requestEnsureConnection(); }catch(Exception e){ // never thrown } Why is the following exception (see below) masked? It is logged out to the JUL but that is of no use to the calling application. The mongo.getConnector().isOpen() also suffers the same fate. Why on earth are these exceptions masked? This is Java 101. WARNING: Exception executing isMaster command on /127.0.0.1:27017 java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect at com.mongodb.DBPort._open(DBPort.java:214) at com.mongodb.DBPort.go(DBPort.java:107) at com.mongodb.DBPort.go(DBPort.java:88) at com.mongodb.DBPort.findOne(DBPort.java:143) at com.mongodb.DBPort.runCommand(DBPort.java:148) at com.mongodb.DBTCPConnector.initDirectConnection(DBTCPConnector.java:548) at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:527) at com.mongodb.DBTCPConnector.requestEnsureConnection(DBTCPConnector.java:129) at com.profiler.ProfilerExtension.run(ProfilerExtension.java:126) at java.lang.Thread.run(Thread.java:619) So the question is, how does one handle the fact a server has gone away? What is the magic here to determine what is what?

    JIRA | 4 years ago | Alan Williamson
    java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
  2. 0

    MongoDB-Java driver: Catch exception when insert fails

    Stack Overflow | 5 years ago | Tigel
    java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
  3. 0

    mongo couldn't connect to [localhost/127.0.0.1:27017]

    Stack Overflow | 3 years ago | asaf app
    java.io.IOException: couldn't connect to [localhost/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    MongoDB with Java, cannot get Collection

    Stack Overflow | 4 years ago | Caveman
    java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
  6. 0

    MongoDB-Java driver: Catch exception when insert fails

    Stack Overflow | 5 years ago | Tigel
    java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect

    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. java.io.IOException

      couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect

      at com.mongodb.DBPort._open()
    2. MongoDB Java Driver
      DBTCPConnector.requestEnsureConnection
      1. com.mongodb.DBPort._open(DBPort.java:214)
      2. com.mongodb.DBPort.go(DBPort.java:107)
      3. com.mongodb.DBPort.go(DBPort.java:88)
      4. com.mongodb.DBPort.findOne(DBPort.java:143)
      5. com.mongodb.DBPort.runCommand(DBPort.java:148)
      6. com.mongodb.DBTCPConnector.initDirectConnection(DBTCPConnector.java:548)
      7. com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:527)
      8. com.mongodb.DBTCPConnector.requestEnsureConnection(DBTCPConnector.java:129)
      8 frames
    3. com.profiler
      ProfilerExtension.run
      1. com.profiler.ProfilerExtension.run(ProfilerExtension.java:126)
      1 frame
    4. Java RT
      Thread.run
      1. java.lang.Thread.run(Thread.java:619)
      1 frame