couldn't connect to [/] Connection refused: connect

JIRA | Alan Williamson | 4 years ago
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  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 / couldn't connect to [/] Connection refused: connect at com.mongodb.DBPort._open( at com.mongodb.DBPort.go( at com.mongodb.DBPort.go( at com.mongodb.DBPort.findOne( at com.mongodb.DBPort.runCommand( at com.mongodb.DBTCPConnector.initDirectConnection( at com.mongodb.DBTCPConnector.checkMaster( at com.mongodb.DBTCPConnector.requestEnsureConnection( at at 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 couldn't connect to [/] Connection refused: connect

    Root Cause Analysis


      couldn't connect to [/] Connection refused: connect

      at com.mongodb.DBPort._open()
    2. MongoDB Java Driver
      1. com.mongodb.DBPort._open(
      2. com.mongodb.DBPort.go(
      3. com.mongodb.DBPort.go(
      4. com.mongodb.DBPort.findOne(
      5. com.mongodb.DBPort.runCommand(
      6. com.mongodb.DBTCPConnector.initDirectConnection(
      7. com.mongodb.DBTCPConnector.checkMaster(
      8. com.mongodb.DBTCPConnector.requestEnsureConnection(
      8 frames
    3. com.profiler
      1 frame
    4. Java RT
      1 frame