Error connection to replica set on Azure Windows VMs

15 views
Skip to first unread message

Mark Watts

unread,
Nov 2, 2018, 6:20:36 AM11/2/18
to node-mongodb-native
Hello,

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,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?



Reply all
Reply to author
Forward
0 new messages