-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 3.1.6
-
Component/s: Concurrency, Storage
-
None
-
Fully Compatible
Found by the hang analyzer in a patch build running noPassthrough/backup_restore.js.
The deadlock involves the "capped in flight" lock and the "local" database lock, and requires the participation of 4 threads.
The first thread is inserting into a replicated capped collection. The second thread is inserting into a replicated plain collection. The third thread is the replication snapshot thread, and the fourth is any thread doing an operation that takes the local database lock in MODE_X, such as createIndexes or replSetReconfig.
The capped insert thread locks its database and collection in MODE_IX, then the "capped in flight" lock in MODE_IX.
The plain insert thread then locks its database and collection in MODE_IX and the local database lock in MODE_IX.
The repl snapshot thread then attempts to get the "capped in flight" lock in MODE_X, and blocks.
The 4th thread then attempts to get the "local" database lock in MODE_X, and blocks behind the plain insert thread.
The capped insert thread then attempts to lock the "local" database in MODE_IX, and blocks behind thread 4.
The plain insert thread then attempts to lock the "capped in flight" lock in MODE_IX and blocks behind the repl snapshot thread.
Now, the capped insert thread is blocked on the fourth thread, which is blocked on the plain insert thread, which is blocked on the snapshot thread, which is blocked on the capped insert thread. Deadlock.