When running a find command on a sharded collection with collectionUUID parameter, there is some special logic in the case where we don't target the primary shard but got a CollectionUUIDMismatch error without an actualCollection. In this case, we go to the primary shard in case the actualCollection is unsharded and thus only exists on that shard. The current logic expects that going to the primary shard will always throw an error (CollectionUUIDMismatch, StaleShardVersion, or StaleDbVersion), however it turns out this is not always the case and it is possible for no error to be thrown. Consider a concurrent collection drop on the collection that is being queried; it will executed in three steps:
- Remove entry from config.collections
- Perform local dropCollection on all non-primary shards
- Perform local dropCollection on the primary shard
If we go to the primary shard between steps 2 and 3, that shard will still have the collection despite not getting a stale version error.