Bug 1721503: Avoid possible lock-order inversion in shutting down RemoteLazyInputStreamChild r=dom-storage-reviewers,edenchuang

Differential Revision: https://phabricator.services.mozilla.com/D134504
This commit is contained in:
Randell Jesup 2021-12-23 12:47:10 +00:00
parent 92b57175c3
commit 9e3ccb99f6

View File

@ -155,17 +155,26 @@ RemoteLazyInputStreamChild::RemoteLazyInputStreamChild(const nsID& aID,
RemoteLazyInputStreamChild::~RemoteLazyInputStreamChild() = default;
void RemoteLazyInputStreamChild::Shutdown() {
MutexAutoLock lock(mMutex);
RefPtr<RemoteLazyInputStreamChild> kungFuDeathGrip = this;
// Don't delete the pending operations inside our lock, since that might
// lead to a lock-ordering inversion
nsTArray<PendingOperation> pending;
{
MutexAutoLock lock(mMutex);
mWorkerRef = nullptr;
mPendingOperations.Clear();
mWorkerRef = nullptr;
pending.SwapElements(mPendingOperations);
if (mState == eActive) {
SendClose();
mState = eInactive;
if (mState == eActive) {
SendClose();
mState = eInactive;
}
}
// Now release pending operations.
// We could let this be destroyed by scope, but I prefer
// to be explicit that we clear this before we drop the
// self-reference
pending.Clear();
}
void RemoteLazyInputStreamChild::ActorDestroy(