The following scenario (at least) can cause an infinite loop in $sample:
- A moveChunk command starts moving a chunk from shard0 to shard1
- $sample begins and a getMore targets shard1
- That getMore uses a cursor that samples randomly with replacement from WiredTiger
- That cursor only fetches one document because the sample size is one, and that document does not belong to that shard because it's in the chunk that's being moved from shard0 to shard1 and does not own it. The ShardFilterStage then filters that document and returns NEEDS_TIME
- The yielding policy is NO_YIELD for some reason so no yielding happens and it tries to sample the cursor again but gets the same document back. This happens infinitely. The yielding behavior may not affect the infinite loop in this case, but it's still unexpected so I'm including it here.