This issue was discovered in C2C:
When sharding a collection with UUID specified, it seems we first check if the collection is capped, then we see if there is a UUID mismatch. As a result, this situation may occur:
- Create a collection, shard it, then drop it, all with UUID1
- Create a collection with the same name but as a capped collection. It now has UUID2
- Kill the replicator and restart it. It begins reapplying events in CEA, starting from the shardCollection with UUID1
- The shardCollection will see that the coll exists with UUID2. We expect it to fail with CollectionUUIDMIsmatch, but it seems server will first check that it is not a capped collection, see that it is, and then return InvalidOptions – can't shard a capped collection, instead of CollectionUUIDMismatch.
SInce mongosync doesn't handle InvalidOptions, it will crash in this situation. Ideally, it seems server should always first check the collection UUID. If there is not a mismatch, then we can proceed with the rest of the validation.
Attached a server-only repro of this issue!