A single aggregation request with $out takes:
- the global lock in IS for a collection lock on the input collection from the client's OperationContext
- the global lock in IS for a collection lock on config.collections and config.chunks from the ShardServerCatalogCacheLoader from one of the loader's OperationContexts
- the global lock in X for renameIfOptionsAndIndexesHaveNotChanged() from the client's OperationContext
Enqueuing a global X lock request blocks all later global lock requests.
So, if one agg request's global X lock request is enqueued in between a second agg request's two global IS lock requests, the three threads can deadlock.
I think it also may be possible for any operation that takes a global X lock to deadlock with a single agg with $out? I am not totally sure though, which is why I titled the ticket as I did for now.
I am not sure whether this affects versions before master, so have just marked it as affecting 4.1.3 for now.