Topology.js error during server selection - docker container based installation

Description

I start my Mongodb with the below shell script. Both MongoDB and RocketChat containers run on the same Ubuntu 23.10 server machine. Host has a IP address.:

sudo docker run -d -t \
	--name mongo6-rocketchat \
	--network="host" \
	--volume $PWD/mongo/etc:/etc/mongo \
	--volume $PWD/mongo/var:/var \
	-e ADMIN_USERNAME=mongoadmin \
	-e ADMIN_PASS=secret \
	-e MONGODB_ROOT_USER=mongoadmin \
	-e MONGODB_ROOT_PASSWORD=secret \
	-e MONGODB_USERNAME=rocketchatuser \
	-e MONGODB_PASSWORD=rocketchatpass \
	-e MONGODB_REPLICA_SET_MODE=primary \
	-e MONGODB_REPLICA_SET_NAME=rs01 \
	-e MONGODB_REPLICA_SET_KEY=rset123 \
	-e MONGODB_ADVERTISED_HOSTNAME=localhost \
	-e MONGODB_PORT_NUMBER=27017 \
	-e MONGODB_INITIAL_PRIMARY_PORT_NUMBER=7017 \
	-e MONGODB_PRIMARY_HOST=primary \
	-e MONGODB_PRIMARY_PORT_NUMBER=27017 \
	-e MONGODB_ENABLE_JOURNAL=true \
	-e MONGODB_ADVERTISED_PORT_NUMBER=true \
	-e ALLOW_EMPTY_PASSWORD=yes \
	docker.io/mongo:6.0

my mongod.conf file is as below:

# mongod.conf

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# Where and how to store data.
storage:
  dbPath: /var/lib/mongo

# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

# network interfaces
net:
  port: 27017
  net.bindIpAll: true

replication:
   oplogSizeMB: 128
   replSetName: rs01
   enableMajorityReadConcern: true

For Rocket Chat, I start with the below shell script:

sudo docker run -d -t \
	--name rocketchat \
	--network="host" \
	--hostname="rktchat" \
	--publish-all=true \
	-e "ROOT_URL=http://10.10.10.35" \
	-e "PORT=3000" \
	-e "MONGO_URL=mongodb://mongoadmin:secret@10.10.10.35:27017/rocketchat?replicaSet=rs01" \
	-e "MONGO_OPLOG_URL=mongodb://mongoadmin:secret@10.10.10.35:27017/local?replicateSet=rs01" \
	docker.io/rocketchat/rocket.chat:6.8.0-alpine

Starting Rocket chat gives me this error which I am unable to comprehend:

$ sudo docker logs rocketchat
/app/bundle/programs/server/npm/node_modules/meteor/promise/node_modules/meteor-promise/promise_server.js:218
      throw error;
      ^

MongoServerSelectionError: Server selection timed out after 30000 ms
    at Timeout._onTimeout (/app/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/sdam/topology.js:292:38)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7)
 => awaited here:
    at Function.Promise.await (/app/bundle/programs/server/npm/node_modules/meteor/promise/node_modules/meteor-promise/promise_server.js:56:12)
    at new MongoConnection (packages/mongo/mongo_driver.js:213:11)
    at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote_collection_driver.js:9:16)
    at Object.<anonymous> (packages/mongo/remote_collection_driver.js:66:18)
    at Object.defaultRemoteCollectionDriver (packages/underscore.js:812:19)
    at new Collection (packages/mongo/collection.js:124:40)
    at AccountsServer._initializeCollection (packages/accounts-base/accounts_common.js:98:20)
    at new AccountsCommon (packages/accounts-base/accounts_common.js:46:23)
    at new AccountsServer (packages/accounts-base/accounts_server.js:30:5)
    at packages/accounts-base/server_main.js:7:12
    at module (packages/accounts-base/server_main.js:19:31)
    at fileEvaluate (packages/modules-runtime.js:336:7)
    at Module.require (packages/modules-runtime.js:238:14)
    at require (packages/modules-runtime.js:258:21)
    at /app/bundle/programs/server/packages/accounts-base.js:2232:15
    at /app/bundle/programs/server/packages/accounts-base.js:2239:3 {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    servers: Map(0) {},
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: 'rs01',
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined,
  [Symbol(errorLabels)]: Set(0) {}
}

For completeness, I see that connection to mongodb is working and below are the logs:

{
  "t": {
    "$date": "2024-05-16T17:25:25.213+00:00"
  },
  "s": "I",
  "c": "CONTROL",
  "id": 8423403,
  "ctx": "initandlisten",
  "msg": "mongod startup complete",
  "attr": {
    "Summary of time elapsed": {
      "Startup from clean shutdown?": true,
      "Statistics": {
        "Transport layer setup": "0 ms",
        "Run initial syncer crash recovery": "0 ms",
        "Create storage engine lock file in the data directory": "0 ms",
        "Get metadata describing storage engine": "0 ms",
        "Create storage engine": "1149 ms",
        "Write current PID to file": "24 ms",
        "Write a new metadata for storage engine": "42 ms",
        "Initialize FCV before rebuilding indexes": "0 ms",
        "Drop abandoned idents and get back indexes that need to be rebuilt or builds that need to be restarted": "0 ms",
        "Rebuild indexes for collections": "0 ms",
        "Build user and roles graph": "0 ms",
        "Set up the background thread pool responsible for waiting for opTimes to be majority committed": "0 ms",
        "Start up the replication coordinator": "0 ms",
        "Start transport layer": "1 ms",
        "_initAndListen total elapsed time": "1556 ms"
      }
    }
  }
}
{
  "t": {
    "$date": "2024-05-16T17:25:25.469+00:00"
  },
  "s": "I",
  "c": "INDEX",
  "id": 20345,
  "ctx": "LogicalSessionCacheRefresh",
  "msg": "Index build: done building",
  "attr": {
    "buildUUID": null,
    "collectionUUID": {
      "uuid": {
        "$uuid": "43a8ca8c-5f7d-4b4c-ba92-50718bf5a9b8"
      }
    },
    "namespace": "config.system.sessions",
    "index": "_id_",
    "ident": "index-5-4292994465689978833",
    "collectionIdent": "collection-4-4292994465689978833",
    "commitTimestamp": null
  }
}
{
  "t": {
    "$date": "2024-05-16T17:25:25.469+00:00"
  },
  "s": "I",
  "c": "INDEX",
  "id": 20345,
  "ctx": "LogicalSessionCacheRefresh",
  "msg": "Index build: done building",
  "attr": {
    "buildUUID": null,
    "collectionUUID": {
      "uuid": {
        "$uuid": "43a8ca8c-5f7d-4b4c-ba92-50718bf5a9b8"
      }
    },
    "namespace": "config.system.sessions",
    "index": "lsidTTLIndex",
    "ident": "index-6-4292994465689978833",
    "collectionIdent": "collection-4-4292994465689978833",
    "commitTimestamp": null
  }
}
{
  "t": {
    "$date": "2024-05-16T17:25:25.469+00:00"
  },
  "s": "I",
  "c": "COMMAND",
  "id": 51803,
  "ctx": "LogicalSessionCacheRefresh",
  "msg": "Slow query",
  "attr": {
    "type": "command",
    "ns": "config.system.sessions",
    "command": {
      "createIndexes": "system.sessions",
      "v": 2,
      "indexes": [
        {
          "key": {
            "lastUse": 1
          },
          "name": "lsidTTLIndex",
          "expireAfterSeconds": 1800
        }
      ],
      "ignoreUnknownIndexOptions": false,
      "writeConcern": {},
      "$db": "config"
    },
    "numYields": 0,
    "reslen": 114,
    "locks": {
      "ParallelBatchWriterMode": {
        "acquireCount": {
          "r": 5
        }
      },
      "FeatureCompatibilityVersion": {
        "acquireCount": {
          "r": 5,
          "w": 1
        }
      },
      "ReplicationStateTransition": {
        "acquireCount": {
          "w": 5
        }
      },
      "Global": {
        "acquireCount": {
          "r": 5,
          "w": 1
        }
      },
      "Database": {
        "acquireCount": {
          "r": 4,
          "w": 1
        }
      },
      "Collection": {
        "acquireCount": {
          "r": 5,
          "w": 1
        }
      },
      "Mutex": {
        "acquireCount": {
          "r": 8
        }
      }
    },
    "storage": {},
    "protocol": "op_msg",
    "durationMillis": 257
  }
}
{
  "t": {
    "$date": "2024-05-16T17:26:10.686+00:00"
  },
  "s": "I",
  "c": "NETWORK",
  "id": 22943,
  "ctx": "listener",
  "msg": "Connection accepted",
  "attr": {
    "remote": "10.10.10.35:53848",
    "uuid": "0a8ce559-4d27-47c7-97dc-4624c61c19d4",
    "connectionId": 1,
    "connectionCount": 1
  }
}
{
  "t": {
    "$date": "2024-05-16T17:26:10.690+00:00"
  },
  "s": "I",
  "c": "NETWORK",
  "id": 51800,
  "ctx": "conn1",
  "msg": "client metadata",
  "attr": {
    "remote": "10.10.10.35:53848",
    "client": "conn1",
    "negotiatedCompressors": [],
    "doc": {
      "driver": {
        "name": "nodejs",
        "version": "4.17.2"
      },
      "platform": "Node.js v14.21.3, LE",
      "os": {
        "name": "linux",
        "architecture": "x64",
        "version": "6.5.0-28-generic",
        "type": "Linux"
      }
    }
  }
}
{
  "t": {
    "$date": "2024-05-16T17:26:10.695+00:00"
  },
  "s": "I",
  "c": "NETWORK",
  "id": 22944,
  "ctx": "conn1",
  "msg": "Connection ended",
  "attr": {
    "remote": "10.10.10.35:53848",
    "uuid": "0a8ce559-4d27-47c7-97dc-4624c61c19d4",
    "connectionId": 1,
    "connectionCount": 0
  }
}

Greatly appreciate any help in getting this error fixed. Thanks!

Server Setup Information

  • Version of Rocket.Chat Server: 6.8.0-alpine
  • Operating System: Ubuntu 23.10
  • Deployment Method: Docker
  • Number of Running Instances: 1
  • DB Replicaset Oplog:
  • NodeJS Version: using docker container
  • MongoDB Version: 6.0
  • Proxy: none
  • Firewalls involved: none

Any additional Information

You probably need to read this.

I would also look at using docker-compose which does a lot of the heavy lifting for you.

You can get the compose file via the docs.

Please note - do NOT use ‘latest’ on a production server. Development only.

Thanks for the references. I will try this. Replication is not important for me. I did not understand the use of it correctly and now I have a better handle on replication. I will remove that and test.
Thanks again

It may not be important to you, but Rocket will not run without replication enabled.

Please come back if you have further issues.

Thanks so much for the guidance. This saved me very valuable time.
Regards

1 Like