Warning
Error Code:
216
MongoDB Error 216: Replica Set Election Active
Description
This error indicates that your MongoDB replica set is currently undergoing an election process to choose a new primary member. This is a normal operational state during failovers, restarts, or when the existing primary becomes unavailable, temporarily impacting write operations.
Error Message
Election In Progress
Known Causes
4 known causesPrimary Node Unavailability
The existing primary member of the replica set has become unresponsive, crashed, or was intentionally shut down.
Network Partition
Network issues have isolated the primary node from a majority of the replica set members, leading to its step down.
Replica Set Reconfiguration
A change to the replica set configuration, such as adding or removing members, can trigger an election.
Member Restart Sequence
Simultaneous or rapid restarts of multiple replica set members, including the primary, can necessitate a new election.
Solutions
4 solutions available1. Wait for Election to Complete easy
The simplest solution is to wait, as elections are temporary.
1
Replica set elections are a normal part of MongoDB's high availability. They occur when the primary node becomes unavailable (e.g., due to network issues, restarts, or crashes). The remaining secondaries hold an election to choose a new primary. This process typically takes a short amount of time (seconds to a few minutes).
text
2
Monitor the replica set status to confirm the election has concluded and a new primary has been elected.
db.replicaSetStatus().state
3
Once the election is complete, your application should be able to connect to the new primary without further intervention.
text
2. Check Replica Set Member Connectivity medium
Ensure all replica set members can communicate with each other.
1
The 'Election In Progress' error can be triggered if replica set members cannot communicate effectively, preventing a stable election. Log in to each replica set member and check network connectivity.
ping <hostname_of_other_member>
2
Verify that the MongoDB ports (default 27017) are open and accessible between all members. Use `telnet` or `nc` to test port connectivity.
telnet <hostname_of_other_member> 27017
3
Review MongoDB logs on all members for any network-related errors or connection refused messages. Ensure the `net.bindIp` configuration correctly allows connections from other replica set members.
text
4
If network issues are identified, resolve them by adjusting firewall rules, ensuring correct DNS resolution, or correcting `net.bindIp` in the `mongod.conf` file.
text
3. Investigate Primary Node Health advanced
Diagnose issues with the current or recently elected primary.
1
If elections are happening frequently or taking too long, the primary node might be experiencing issues. Connect to the primary (if accessible) or a secondary and check its health.
db.serverStatus()
2
Examine the `connections` and `network` sections of `serverStatus` for any anomalies, such as excessive connections or high network traffic. Also, check the `globalLock` for any indications of prolonged lock contention.
text
3
Review the MongoDB logs on the primary for any errors related to disk I/O, memory, or application-level issues that might be causing it to become unresponsive or crash.
text
4
If the primary is consistently unhealthy, consider restarting it gracefully. If the issue persists, investigate the underlying cause (e.g., resource exhaustion, problematic queries, or hardware problems) and address it. In severe cases, you might need to initiate a manual failover.
text
4. Verify Replica Set Configuration medium
Ensure the replica set configuration is sound and members are correctly defined.
1
Incorrect replica set configuration can lead to election instability. Connect to any member of the replica set and run `rs.conf()` to view the current configuration.
rs.conf()
2
Carefully review the `members` array in the configuration. Ensure that all hostnames and ports are accurate, and that each member is correctly identified with its `_id` and `host`.
text
3
Check the `priority` settings. A priority of 0 means a member cannot be elected primary. Ensure at least one member has a non-zero priority. Also, verify `votes` are correctly assigned.
text
4
If the configuration is incorrect, use `rs.reconfig()` to update it. **Caution:** Incorrectly reconfiguring a replica set can lead to data loss or downtime. Always back up your configuration before making changes.
rs.reconfig(newConfig, { force: true })