Commit 9e3ccb99 authored by Randell Jesup's avatar Randell Jesup
Browse files

Bug 1721503: Avoid possible lock-order inversion in shutting down...

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

Differential Revision: https://phabricator.services.mozilla.com/D134504
parent 92b57175
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -155,18 +155,27 @@ 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();
    pending.SwapElements(mPendingOperations);

    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(
    IProtocol::ActorDestroyReason aReason) {