Bug 1919788 introduced calling OpenClientDirectory as a first step, which made
it possible for PrepareDatastoreOp::CheckExistingOperations to not be called in
the same order as the operations were created. If OpenClientDirectory is called
multiple times with the same arguments, the promises can be resolved/rejected
in random order. This issue became even more apparent after bug 1866402, which
added origin initialization to OpenClientDirectory.
The serialization based on mDelayedOp can only reliably work if
CheckExistingOperations is invoked in the same order as operations are created.
Therefore, the operations now utilize a more sophisticated method to track
dependencies.
This fix implements a robust dependency tracking mechanism using mBlocking and
mBlockedOn lists, ensuring that each PrepareDatastoreOp proceeds in a
serialized manner based on its dependencies, thereby maintaining the correct
order of operations and enhancing stability in datastore preparations.
Differential Revision: https://phabricator.services.mozilla.com/D227985