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

Replicaset Connectivity Issue from Docker and 3.6.x

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.4
    • Affects Version/s: 3.6.3
    • Component/s: None
    • Labels:
      None

      I'm not sure if this would be a regression from 3.6.x or a bug that was fixed in 3.6.x however given the following MongoDB cluster (single node replica set running in docker) the test will succeed in 3.5 and fail in 3.6.

      docker-compose.yml

      version: "3"
      services: 
        mongodb: 
         image: mongo:4.4.1-bionic
         environment: 
           MONGO_REPLICA_SET_NAME: rs0
         expose: 
           - 27017
         ports: 
           - "27017:27017"
         healthcheck: 
           test: test $$(echo "rs.initiate().ok || rs.slaveOk().ok || rs.status().ok" | mongo --quiet) -eq 1
           interval: 10s
           start_period: 30s
         entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ]
      

      index.js

      const { MongoClient } = require('mongodb');
      
      const url = "mongodb://127.0.0.1:27017/test?replSet=rs0'"
      const options = {
        useNewUrlParser: true,
        useUnifiedTopology: true
      };
      
      console.log('connecting to', url);
      
      var client = new MongoClient(url, options);
      
      client.on('serverDescriptionChanged', function(event) {
        console.log('received serverDescriptionChanged');
        console.log(JSON.stringify(event, null, 2));
      });
      
      client.on('serverHeartbeatStarted', function(event) {
        console.log('received serverHeartbeatStarted');
        console.log(JSON.stringify(event, null, 2));
      });
      
      client.on('serverHeartbeatSucceeded', function(event) {
        console.log('received serverHeartbeatSucceeded');
        console.log(JSON.stringify(event, null, 2));
      });
      
      client.on('serverHeartbeatFailed', function(event) {
        console.log('received serverHeartbeatFailed');
        console.log(JSON.stringify(event, null, 2));
      });
      
      client.on('serverOpening', function(event) {
        console.log('received serverOpening');
        console.log(JSON.stringify(event, null, 2));
      });
      
      client.on('serverClosed', function(event) {
        console.log('received serverClosed');
        console.log(JSON.stringify(event, null, 2));
      });
      
      client.on('topologyOpening', function(event) {
        console.log('received topologyOpening');
        console.log(JSON.stringify(event, null, 2));
      });
      
      client.on('topologyClosed', function(event) {
        console.log('received topologyClosed');
        console.log(JSON.stringify(event, null, 2));
      });
      
      client.on('topologyDescriptionChanged', function(event) {
        console.log('received topologyDescriptionChanged');
        console.log(JSON.stringify(event, null, 2));
      });
      
      client.connect()
        .then(() => {
          console.log('ok')
        })  .catch((err) => console.error('error', err));
      

      To run the test:

      docker-compose up -d
      npm install mongodb@3.5.10 --save && node index.js
      npm install mongodb@3.6.3 --save && node index.js
      

      The test above shows the serverDescriptionChanged events differ, and as a result the serverOpening event is targeting an IP address (in 3.5.x) as opposed to a hostname (in 3.6.x)

      // 3.5 Topology Events
      
      received serverOpening
      {
        "topologyId": 0,
        "address": "127.0.0.1:27017"
      }
      received serverHeartbeatStarted
      {
        "connectionId": "127.0.0.1:27017"
      }
      received serverHeartbeatSucceeded
      {
        "connectionId": "127.0.0.1:27017",
        "duration": 26,
        "reply": {
          "topologyVersion": {
            "processId": "5faaebc4119ee19f2d5dccf5",
            "counter": 6
          },
          "hosts": [
            "mongodb:27017"
          ],
          "setName": "rs0",
          "setVersion": 1,
          "ismaster": true,
          "secondary": false,
          "primary": "mongodb:27017",
          "me": "mongodb:27017",
          "electionId": "7fffffff0000000000000002",
          "lastWrite": {
            "opTime": {
              "ts": "6893584559196078081",
              "t": 2
            },
            "lastWriteDate": "2020-11-10T19:48:50.000Z",
            "majorityOpTime": {
              "ts": "6893584559196078081",
              "t": 2
            },
            "majorityWriteDate": "2020-11-10T19:48:50.000Z"
          },
          "maxBsonObjectSize": 16777216,
          "maxMessageSizeBytes": 48000000,
          "maxWriteBatchSize": 100000,
          "localTime": "2020-11-10T19:48:53.620Z",
          "logicalSessionTimeoutMinutes": 30,
          "connectionId": 81,
          "minWireVersion": 0,
          "maxWireVersion": 9,
          "readOnly": false,
          "ok": 1,
          "$clusterTime": {
            "clusterTime": "6893584559196078081",
            "signature": {
              "hash": {
                "type": "Buffer",
                "data": [
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0
                ]
              },
              "keyId": 0
            }
          },
          "operationTime": "6893584559196078081"
        }
      }
      received serverDescriptionChanged
      {
        "topologyId": 0,
        "address": "127.0.0.1:27017",
        "previousDescription": {
          "address": "127.0.0.1:27017",
          "roundTripTime": -1,
          "lastUpdateTime": 1322597506,
          "lastWriteDate": null,
          "opTime": null,
          "type": "Unknown",
          "minWireVersion": 0,
          "maxWireVersion": 0,
          "hosts": [],
          "passives": [],
          "arbiters": [],
          "tags": []
        },
        "newDescription": {
          "address": "127.0.0.1:27017",
          "roundTripTime": 26,
          "lastUpdateTime": 1322597542,
          "lastWriteDate": "2020-11-10T19:48:50.000Z",
          "opTime": {
            "ts": "6893584559196078081",
            "t": 2
          },
          "type": "RSPrimary",
          "minWireVersion": 0,
          "maxWireVersion": 9,
          "maxBsonObjectSize": 16777216,
          "maxMessageSizeBytes": 48000000,
          "maxWriteBatchSize": 100000,
          "me": "mongodb:27017",
          "hosts": [
            "mongodb:27017"
          ],
          "passives": [],
          "arbiters": [],
          "tags": [],
          "setName": "rs0",
          "setVersion": 1,
          "electionId": "7fffffff0000000000000002",
          "primary": "mongodb:27017",
          "logicalSessionTimeoutMinutes": 30,
          "$clusterTime": {
            "clusterTime": "6893584559196078081",
            "signature": {
              "hash": {
                "type": "Buffer",
                "data": [
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0
                ]
              },
              "keyId": 0
            }
          }
        }
      }
      
      // 3.6 Topology Events
      received serverOpening
      {
        "topologyId": 0,
        "address": "127.0.0.1:27017"
      }
      received serverHeartbeatStarted
      {
        "connectionId": "127.0.0.1:27017"
      }
      received serverHeartbeatSucceeded
      {
        "connectionId": "127.0.0.1:27017",
        "duration": 30,
        "reply": {
          "topologyVersion": {
            "processId": "5faaebc4119ee19f2d5dccf5",
            "counter": 6
          },
          "hosts": [
            "mongodb:27017"
          ],
          "setName": "rs0",
          "setVersion": 1,
          "ismaster": true,
          "secondary": false,
          "primary": "mongodb:27017",
          "me": "mongodb:27017",
          "electionId": "7fffffff0000000000000002",
          "lastWrite": {
            "opTime": {
              "ts": "6893584730994769921",
              "t": 2
            },
            "lastWriteDate": "2020-11-10T19:49:30.000Z",
            "majorityOpTime": {
              "ts": "6893584730994769921",
              "t": 2
            },
            "majorityWriteDate": "2020-11-10T19:49:30.000Z"
          },
          "maxBsonObjectSize": 16777216,
          "maxMessageSizeBytes": 48000000,
          "maxWriteBatchSize": 100000,
          "localTime": "2020-11-10T19:49:39.876Z",
          "logicalSessionTimeoutMinutes": 30,
          "connectionId": 86,
          "minWireVersion": 0,
          "maxWireVersion": 9,
          "readOnly": false,
          "ok": 1,
          "$clusterTime": {
            "clusterTime": "6893584730994769921",
            "signature": {
              "hash": {
                "type": "Buffer",
                "data": [
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0,
                  0
                ]
              },
              "keyId": 0
            }
          },
          "operationTime": "6893584730994769921"
        }
      }
      received serverDescriptionChanged
      {
        "topologyId": 0,
        "address": "127.0.0.1:27017",
        "previousDescription": {
          "address": "127.0.0.1:27017",
          "roundTripTime": -1,
          "lastUpdateTime": 1322643760,
          "lastWriteDate": null,
          "opTime": null,
          "type": "Unknown",
          "minWireVersion": 0,
          "maxWireVersion": 0,
          "hosts": [],
          "passives": [],
          "arbiters": [],
          "tags": []
        }
      }
      

            Assignee:
            eric.adum@mongodb.com Eric Adum (Inactive)
            Reporter:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Votes:
            6 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved: