Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1475

MongoClient failed to connect to server on first connect, but connects later

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 3.0.7
    • 3.2.2
    • Core

    Description

      I explained the problem in detail on Stack Overflow, but I think this behaviour is a bug and should be reported here as well.

      In brief, when MongoClient.connect fails with the error:
      MongoNetworkError: failed to connect to server [mongo:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 172.18.0.2:27017]
      It rejects the promise, but it continues to retry to connect and when it's successful it's not reported to the promise (or callback), which means that I cannot use the connection, but it's there and continues to exist until the application is closed.

      Currently when this happens I retry by calling MongoClient.connect again and for each failure I get a new connection, but at some point I get a connection that I can actually use. At this point the app might have hundreds of connections to the database, but only one usable. Besides terminating the app, I don't have any way of closing the unused connections. The database logs clearly shows that they are opened, but never closed, until the app is terminated.

      I don't think this behaviour is useful and I didn't find anything about this in the documentation, so I'm assuming that it's unintended and hence a bug. If there is any recommended workaround I would be very interested, as I'm not very happy with my current workaround.

       

      Attachments

        Issue Links

          Activity

            People

              matt.broadstone@mongodb.com Matt Broadstone
              erik.blomqvist Erik Blomqvist
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: