The server is shutting down
This error occurs when a client sends an operation to a `mongod` or `mongos` instance that is in the process of shutting down. The server will refuse to process new requests to ensure an orderly shutdown.
- 1An administrator has initiated a shutdown of the MongoDB server
- 2The server is undergoing a rolling restart as part of a maintenance procedure
- 3In a replica set, the primary is stepping down, and a failover is in progress
- 4An automated script or process is restarting the MongoDB service
A client sends a query to a `mongod` instance immediately after a `shutdown` command has been issued.
// In one shell, initiate shutdown:
use admin
db.shutdownServer()
// In a second shell, an operation sent just after will fail:
db.test.find({})expected output
MongoServerError: shutdown in progress
Fix 1
Implement Connection Retry Logic
WHEN This error occurs in a replica set or sharded cluster environment.
Why this works
Modern MongoDB drivers have built-in retry logic for this scenario. During a failover, it is normal to see this error temporarily. The driver should automatically detect the new primary and retry the operation. Ensure `retryWrites` and `retryReads` are enabled.
Fix 2
Ensure Graceful Shutdown Procedures
WHEN Performing maintenance.
Why this works
When shutting down a server for maintenance, ensure that application traffic is first drained or redirected. Use a shutdown procedure that allows in-flight operations to complete before the server terminates.
✕ Treat this error as a fatal, unrecoverable event in a replica set
In a high-availability environment, this error is a normal part of the failover process. The application should be resilient to it and retry the connection/operation after a short delay.
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev