You operate a sharded Mongo cluster — 3 config servers, 4 shards in PSS. One Tuesday afternoon the data-team Slack lights up: their nightly job has been failing for two hours with Could not find host matching read preference. Nothing else is alerting. The application is mostly fine, except for the operations that just-now happen to need a chunk split, which silently time out. You check sh.status() from a mongos and it hangs. The config server replica set has been degraded since last night, and nothing on your monitoring plane fired.
What’s happening
The config server replica set (CSRS) holds the sharded cluster’s metadata: which shard owns which chunk, what mongos routers exist, balancer state, and which collections are sharded on what key. Every routed operation touches this metadata at some point — either reading it (mongos must know which shard to send a query to) or modifying it (chunk splits, balancer moves, new collection sharding).
When CSRS loses majority — i.e., two of three config servers are unreachable or degraded — the cluster enters a strange state:
- Reads of existing chunks keep working. mongos has the cached chunk map from before CSRS went bad; routed reads against sharded collections continue. This is what makes the failure mode insidious — the application looks fine.
- Reads of metadata fail.
sh.status(),db.collection.getShardDistribution(), anything that goes to CSRS at runtime, hangs or fails with aNotPrimaryOrSecondaryerror. - Writes that need metadata fail. Chunk splits stop happening. The balancer stops. New shards can’t be added. New collections can’t be sharded. Authentication via the cluster (rather than locally on each shard) breaks because the user catalog lives in the config DB.
- Unsharded collections in the config database become read-only. Anything that needs to commit through the config primary blocks.
The cluster does not “stop” in a way that triggers obvious alerts. It limps along on cached metadata until the first cache miss, at which point a small fraction of operations fail. By the time you correlate the symptoms, you’ve been degraded for hours.
How to verify
Direct CSRS health check (this is the canary):
mongosh --tls --tlsCAFile /etc/mongo/tls/ca.pem \
--tlsCertificateKeyFile /etc/mongo/tls/client.pem \
--host cfg01.internal --port 27019 \
--eval "rs.status()" \
| jq '.members[] | {name, stateStr, health, lastHeartbeatRecv}'
# [
# { "name": "cfg01.internal:27019", "stateStr": "PRIMARY", "health": 1, ... },
# { "name": "cfg02.internal:27019", "stateStr": "(not reachable/healthy)", "health": 0, ... },
# { "name": "cfg03.internal:27019", "stateStr": "SECONDARY", "health": 1, ... }
# ]
Health 0 on any member is the first warning. Two members at health 0 means CSRS has lost majority — the surviving node is in SECONDARY and the cluster is read-only for metadata.
Check sh.status() from mongos — if it hangs or errors out, CSRS is the problem:
mongosh --tls --tlsCAFile /etc/mongo/tls/ca.pem \
--tlsCertificateKeyFile /etc/mongo/tls/client.pem \
--host mongos01.internal --eval "sh.status()" \
| head -10
Balancer state — if it stopped recently and you didn’t stop it, that’s evidence:
sh.getBalancerState() // false unexpectedly?
sh.isBalancerRunning() // shouldn't have just stopped
db.getSiblingDB("config").changelog.find({what: "balancer.stop"}).sort({time:-1}).limit(3)
mongos logs around the symptom time will show config-server connection errors and election retries:
tail -200 /var/log/mongo/mongos.log | grep -iE 'config|csrs|election|not primary'
The fix
The first priority is restoring CSRS majority. Don’t restart the cluster; you’ll lose any in-flight chunk splits and force a balancer recheck which is what you don’t want during an incident.
Triage the unhealthy CSRS members one at a time:
# On the unhealthy member
sudo systemctl status mongod
sudo journalctl -u mongod --since "2 hours ago" | tail -100
# Check disk + memory
df -h /var/lib/mongo
free -m
# Check the mongod log for the underlying failure
tail -200 /var/log/mongo/mongod.log
Common causes you’ll find here: data volume filled up, OOM kill (set vm.swappiness=1 and a sensible cache size to prevent), clock skew between CSRS members (NTP drift past several seconds breaks the heartbeat), TLS cert expired (the CA-signed per-node certs are 365 days by default in our installer; renewals are not automatic).
If the issue is recoverable (restart mongod after fixing disk/clock/cert):
sudo systemctl restart mongod
# Wait for it to rejoin the replica set
mongosh --tls --tlsCAFile /etc/mongo/tls/ca.pem \
--tlsCertificateKeyFile /etc/mongo/tls/cfg01.pem \
--host cfg01.internal --port 27019 --eval "rs.status()" \
| jq '.members[] | {name, stateStr, health}'
Once health: 1 is back on two of three, CSRS regains majority and the cluster recovers. sh.status() from mongos starts responding again within seconds.
If a CSRS member has lost data (volume corruption, etc.):
You need to rebuild it from a surviving member. Stop mongod on the bad member, remove the data directory, restart — it will perform an initial sync from the primary. This is a metadata-only sync (much smaller than a shard’s data) and usually completes in minutes.
sudo systemctl stop mongod
sudo rm -rf /var/lib/mongo/*
sudo systemctl start mongod
# Watch for "transition to SECONDARY" in /var/log/mongo/mongod.log
Add the following four alerts so this never goes unnoticed again:
- CSRS member health < 1 for > 60s. Page-tier alert. This is the canary.
sh.status()from mongos takes > 5s. A simple synthetic check from a non-mongos host, run every minute, that times out fast. If it can’t get a response, CSRS is degraded.- Balancer disabled when you didn’t disable it. Watch the config.changelog collection for
balancer.stopevents not preceded by an operator action. - mongos cannot reach CSRS for > 30s. Log-scrape mongos for
unable to find host matching read preferenceorCould not contact primary for config server.
For the cluster to survive a single CSRS node failure cleanly, the underlying nodes must be on diverse failure domains — different availability zones if your cloud has them, or at least different hypervisor hosts on bare-metal. Three config nodes on the same hypervisor is a single point of failure dressed up as HA.
Stack Harbor’s monitoring plane includes the four CSRS alerts above for every sharded Mongo cluster we run under Managed Cloud Ops — and a quarterly chaos drill that pulls a CSRS node mid-business-hours to confirm the alerts and the runbook still work. Talk to us if your current monitoring doesn’t catch this.