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

Replica set causes MongoNetworkError due to not connecting with fully qualified domain name

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 3.1.0
    • Fix Version/s: 3.3.5
    • Component/s: core
    • Labels:
    • MongoDB Version:
      Not Applicable

      Description

      We have a replica set across three Azure Windows VMs. When a Node.js application hosted on a separate Windows VM, and when it tries to connect we get this error:

       

      ERROR MongoNetworkError: failed to connect to server [server01:27017] on first connect [MongoNetworkError: getaddrinfo ENOTFOUND server01 server01:27017]

      Applications written in C# can connect without issue, as can the MongoDB CLI.

      We are using mongodb-core v3.1.0. After adding some console logging to mongodb-core\lib\connection\connection.js (around line 595) it looks like the cause of the problem
      is that the driver is removing the domain qualification from the server names. Our connection string is mongodb://SERVER01.domain.company.com,[SERVER02.domain.company.com|http://server02.domain.company.com/],[SERVER03.domain.company.com|http://server03.domain.company.com/]. 
      Initially connections are made to all 3 nodes using the FQDN (first using IPv6 then falling back to IPv4), but immediately afterwards connections are attempted using just the host name, which fails.

      Example logs:

       

      MONGODB CONNECTION
      { port: 27017,
        host: 'SERVER01.domain.company.com',
        family: 6 }
      MONGODB CONNECTION
      { port: 27017,
        host: 'SERVER02.domain.company.com',
        family: 6 }
      MONGODB CONNECTION
      { port: 27017,
        host: 'SERVER03.domain.company.com',
        family: 6 }
      MONGODB CONNECTION
      { port: 27017,
        host: 'SERVER01.domain.company.com',
        family: 4 }
      MONGODB CONNECTION
      { port: 27017,
        host: 'SERVER02.domain.company.com',
        family: 4 }
      MONGODB CONNECTION
      { port: 27017,
        host: 'SERVER03.domain.company.com',
        family: 4 }
      MONGODB CONNECTION
      { port: 27017, host: 'server01', family: 6 }
      MONGODB CONNECTION
      { port: 27017, host: 'server02', family: 6 }
      MONGODB CONNECTION
      { port: 27017, host: 'server03', family: 6 }
      MONGODB CONNECTION
      { port: 27017, host: 'server03', family: 4 }
      MONGODB CONNECTION
      { port: 27017, host: 'server02', family: 4 }
      MONGODB CONNECTION
      { port: 27017, host: 'server01', family: 4 }

      When there is no replica set only the initial connection, using the FQDN, is made. Oddly, Node's DNS can resolve both SERVER01.domain.company.com and server01 to the correct IP address, e.g. using dns.lookup.

      Is this a bug in the driver, or are we missing some configuration somewhere?

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: