91
MongoDBERRORSystemHIGH confidence

The server is shutting down

What this means

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.

Why it happens
  1. 1An administrator has initiated a shutdown of the MongoDB server
  2. 2The server is undergoing a rolling restart as part of a maintenance procedure
  3. 3In a replica set, the primary is stepping down, and a failover is in progress
  4. 4An automated script or process is restarting the MongoDB service
How to reproduce

A client sends a query to a `mongod` instance immediately after a `shutdown` command has been issued.

trigger — this will error
trigger — this will error
// 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.

What not to do

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.

Sources
Official documentation ↗

mongodb/mongo src/mongo/base/error_codes.yml

Replica Set Failovers

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MongoDB errors