13388 — StaleConfig

sharding

The shard's cached routing information is stale

What is happening?

StaleConfig (also known as StaleShardVersion) occurs when a shard receives a request with routing metadata that does not match its current chunk ownership. This happens after chunk migrations when the routing tables are being refreshed. Drivers and mongos typically retry transparently.

Common causes

  1. Chunk migration just completed
  2. Balancer is actively moving chunks
  3. mongos routing cache is stale
  4. Collection dropped and recreated with different shard key

Source code references

ErrorCodes::StaleConfig found in 45 locations in the MongoDB server source.

Diagnostic Steps

Related Issues

SERVER-138551Needs Scheduling
StaleConfig error when $unionWith pipeline begins with $collStats in random shard passthough
An aggregation whose pipeline contains a {{$unionWith}} whose sub-pipeline begins with a cursorless stage ({{{}$collStats{}}}) fails with a *non-retryable* StaleConfig ("timestamp mismatch detected") whenever the node that executes the {{$unionWith}} is not the shard that owns the foreign collection. This is hit deterministically on clusters where tracked unsplittable collections live off the merging node (e.g. after {{{}moveCollection{}}}, or when unsharded collections are tracked upon creation
SERVER-88498Closed
Retry analyzeShardKey command on StaleConfig error even when balancer is off for FSM test
Currently the analyze_shard_key.js FSM test only retries StaleConfig errors for the analyzeShardKey command when the balancer is on. But it is possible to get StaleConfig errors even when the balancer is not on. Instead, the analyzeShardKey command should always be retried on StaleConfig error and not be conditional on the balancer being on.
SERVER-137806Closed
Analyze shard key background hook should not try to analyze temporary resharding collection
This is causing BF-46817, where the hook tries to [run a find|https://github.com/10gen/mongo/blob/40b9e7144056805376bed7f0ef3808343d6bf9cb/jstests/hooks/run_analyze_shard_key_background.js#L309-L312] on the temporary resharding collection to determine a possible shard key to analyze. But the temporary resharding collection was dropped resulting in repeated StaleConfig errors.
SERVER-118789Closed
StaleConfig is currently being handled in two different places
We currently have duplicated stale-routing handling logic, in [router_role.cpp|https://github.com/mongodb/mongo/blob/db370e873b09f297e944fc484d4134fe52c7c63f/src/mongo/db/router_role/router_role.cpp#L196-L212], and in [routing_context.cpp|https://github.com/mongodb/mongo/blob/3d9e1ce11d26df5b0cf0d6fef1167388170e09b8/src/mongo/db/router_role/routing_context.cpp#L206-L220]. The one from the routing context is only used from [write_batch_response_processor.cpp.|https://github.com/10gen/mongo/blo