Save settings deadlock
|Reported by:||a.urakov||Owned by:|
|Keywords:||save, settings, deadlock, media||Cc:|
|Guest type:||all||Host type:||Linux|
There is possible deadlock on medium access when different machines save their settings. Deadlock occurs when these machines are commiting medias and saving modified registries at the same time.
In our case there are two machines (1 and 2) cloned with link option from common machine. We take snapshots of machines at the same time. So machine 1 saves modified registries (VirtualBox::saveModifiedRegistries()) for machine common (because information about 1 medias is saved in common settings due to linked cloning). Eventually it calls VirtualBox::saveMediaRegistry() which holds read lock on common medium and calls Medium::saveSettings() for every children. This recurses through all children mediums of common and holds read locks on all current recursion branch. So it tries to get read lock on 2 medium.
At the same time machine 2 commits media (Machine::commitMedia()). When it converts implicit attachment to normal it holds write lock on parent medium (the same medium thread 1 waits for) and tries to unlock all locked by session mediums (here I mean IMedium API-level locking, not object locking). Unlock procedure MediumLockList::Unlock() eventually calls Medium::unlockRead() for each medium in locked list (and common medium too). Medium::unlockRead() tries to get common medium write lock so threads are deadlocked.
Thank you in advance!