Replica sets with IPv6 addresses for the host field fail to connect properly

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.1.19
    • Component/s: Core
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      With replica set configuration using IPv6 addresses directly (not hostnames), when connecting to the replica set, the connection fails.

      Example:

      {
      	"_id" : "myReplSet",
      	"version" : 5,
      	"protocolVersion" : 65,
      	"members" : [
      		{
      			"_id" : 0,
      			"host" : "2607:f160:10:401b:ce:9:0:2:27017"
      		},
      		{
      			"_id" : 1,
      			"host" : "2607:f160:10:401b:ce:9:0:1:27017",
      			"votes" : 0,
      			"priority" : 0
      		}
      	]
      }
      

      When connecting to mongodb://localhost:27017/myDb?replicaSet=myReplSet, it fails to connect. Previous versions worked.

      The error is in
      https://github.com/mongodb-js/mongodb-core/blob/v2.1.19/lib/topologies/replset.js#L328

      host: _server.split(':')[0],
      port: parseInt(_server.split(':')[1], 10)

      which is splitting the string on the first ':' instead of the last.

      simple fix:

      host: _server.substring(0, _server.lastIndexOf(':')),
      port: parseInt(_server.substring(_server.lastIndexOf(':')+1), 10)

            Assignee:
            Daniel Aprahamian (Inactive)
            Reporter:
            Jon Engle
            None
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: