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

mongodb-core no longer throws MongoNetworkError on first connect failure

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.2.4
    • Affects Version/s: 3.2.0
    • Component/s: Core
    • Labels:
    • Environment:
      Node.js version 8.16.0
      Ubuntu Linux 18.04

      Since mongodb-core 3.2.0, connection failure on first connect no longer throws a MongoNetworkError. Instead, an unwrapped error from TCPConnectWrap is thrown.

      How to recreate:

      1. Create a new Node.js project. Then, install mongodb-core 3.2.0.
      2. Add this code to index.js:
         var Server = require('mongodb-core').Server
         var server = new Server({
           host: 'localhost'
           , port: 27017
           , reconnect: true
           , reconnectInterval: 50
         });
         server.connect();
        

        (This code is actually straight from the documentation.)

      3.  Make sure no server is listening on that port, then run node index.js
        Expected result: Node stops with MongoNetworkError, as it was on mongodb-core 3.1
        Actual result: Node stops with the following error:
          events.js:183
             throw er; // Unhandled 'error' event
             ^
        
        Error: connect ECONNREFUSED 127.0.0.1:27017
             at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
        

      For reference, this is how the error looks like on mongodb-core 3.1.11 (the lastest version on 3.1 line):

      events.js:183
            throw er; // Unhandled 'error' event
            ^
       
      MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
          at Pool.<anonymous> (<project dir>/node_modules/mongodb-core/lib/topologies/server.js:564:11)
          at emitOne (events.js:116:13)
          at Pool.emit (events.js:211:7)
          at Connection.<anonymous> (<project dir>/node_modules/mongodb-core/lib/connection/pool.js:317:12)
          at Object.onceWrapper (events.js:317:30)
          at emitTwo (events.js:126:13)
          at Connection.emit (events.js:214:7)
          at Socket.<anonymous> (<project dir>/node_modules/mongodb-core/lib/connection/connection.js:246:50)
          at Object.onceWrapper (events.js:315:30)
          at emitOne (events.js:116:13)
      

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            peat_psuwit Ratchanan Srirattanamet
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: