Commit cdc702ad authored by Honza Bambas's avatar Honza Bambas
Browse files

Bug 1605895 - Add a diagnostic assertion when an http channel on the child...

Bug 1605895 - Add a diagnostic assertion when an http channel on the child process loading CSS does not notify OnStopRequest before being destroyed, r=michal

Differential Revision: https://phabricator.services.mozilla.com/D68025

--HG--
extra : moz-landing-system : lando
parent 0113f657
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1636,6 +1636,12 @@ nsresult Loader::LoadSheet(SheetLoadData& aLoadData, SheetState aSheetState,
    return rv;
  }

#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
  if (nsCOMPtr<nsIHttpChannelInternal> hci = do_QueryInterface(channel)) {
    hci->DoDiagnosticAssertWhenOnStopNotCalledOnDestroy();
  }
#endif

  mSheets->mLoadingDatas.Put(&key, &aLoadData);
  aLoadData.mIsLoading = true;

+2 −0
Original line number Diff line number Diff line
@@ -733,5 +733,7 @@ NS_IMETHODIMP ClassifierDummyChannel::IsThirdPartySocialTrackingResource(
  return NS_OK;
}

void ClassifierDummyChannel::DoDiagnosticAssertWhenOnStopNotCalledOnDestroy() {}

}  // namespace net
}  // namespace mozilla
+2 −0
Original line number Diff line number Diff line
@@ -4504,5 +4504,7 @@ void HttpBaseChannel::MaybeFlushConsoleReports() {
  }
}

void HttpBaseChannel::DoDiagnosticAssertWhenOnStopNotCalledOnDestroy() {}

}  // namespace net
}  // namespace mozilla
+1 −0
Original line number Diff line number Diff line
@@ -329,6 +329,7 @@ class HttpBaseChannel : public nsHashPropertyBag,
  }
  NS_IMETHOD HTTPUpgrade(const nsACString& aProtocolName,
                         nsIHttpUpgradeListener* aListener) override;
  void DoDiagnosticAssertWhenOnStopNotCalledOnDestroy() override;

  // nsISupportsPriority
  NS_IMETHOD GetPriority(int32_t* value) override;
+29 −0
Original line number Diff line number Diff line
@@ -204,6 +204,18 @@ HttpChannelChild::HttpChannelChild()
HttpChannelChild::~HttpChannelChild() {
  LOG(("Destroying HttpChannelChild @%p\n", this));

#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
  if (mDoDiagnosticAssertWhenOnStopNotCalledOnDestroy && mAsyncOpenSucceeded &&
      !mSuccesfullyRedirected && !mOnStopRequestCalled) {
    MOZ_CRASH_UNSAFE_PRINTF(
        "~HttpChannelChild %p, mOnStopRequestCalled=false, mStatus=0x%08x, "
        "mActorDestroyReason=%d, mRedirectChannelChild=%p",
        this, static_cast<uint32_t>(nsresult(mStatus)),
        static_cast<int32_t>(mActorDestroyReason ? *mActorDestroyReason : -1),
        mRedirectChannelChild.get());
  }
#endif

  ReleaseMainThreadOnlyReferences();
}

@@ -1941,6 +1953,9 @@ bool HttpChannelChild::Redirect3Complete(OverrideRunnable* aRunnable) {
      httpChannelChild->mInterceptingChannel = this;
    }
    rv = mRedirectChannelChild->CompleteRedirectSetup(mListener);
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
    mSuccesfullyRedirected = NS_SUCCEEDED(rv);
#endif
  }

  if (!httpChannelChild || !httpChannelChild->mShouldParentIntercept) {
@@ -2390,6 +2405,10 @@ HttpChannelChild::AsyncOpen(nsIStreamListener* aListener) {

    gHttpHandler->OnFailedOpeningRequest(this);
  }

#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
  mAsyncOpenSucceeded = NS_SUCCEEDED(rv);
#endif
  return rv;
}

@@ -3898,6 +3917,10 @@ mozilla::ipc::IPCResult HttpChannelChild::RecvCancelDiversion() {
void HttpChannelChild::ActorDestroy(ActorDestroyReason aWhy) {
  MOZ_ASSERT(NS_IsMainThread());

#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
  mActorDestroyReason.emplace(aWhy);
#endif

  // OnStartRequest might be dropped if IPDL is destroyed abnormally
  // and BackgroundChild might have pending IPC messages.
  // Clean up BackgroundChild at this time to prevent memleak.
@@ -3981,5 +4004,11 @@ nsresult HttpChannelChild::CrossProcessRedirectFinished(nsresult aStatus) {
  return mStatus;
}

void HttpChannelChild::DoDiagnosticAssertWhenOnStopNotCalledOnDestroy() {
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
  mDoDiagnosticAssertWhenOnStopNotCalledOnDestroy = true;
#endif
}

}  // namespace net
}  // namespace mozilla
Loading