Bug 1383025 - Don't report hang for a process that has already shut down. r=billm
authorCervantes Yu <cyu@mozilla.com>
Fri, 28 Jul 2017 16:55:16 +0800
changeset 420404 c5ccbf267da5f2e4162f3d33125689d8f7cbf7c1
parent 420319 91c459dd13e5d05cd5b707ae717801a6b04d6031
child 420405 e781433714c456eb678826fb00725a630e88c736
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1383025
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1383025 - Don't report hang for a process that has already shut down. r=billm MozReview-Commit-ID: 5H1CYYJIiM6
dom/ipc/ProcessHangMonitor.cpp
--- a/dom/ipc/ProcessHangMonitor.cpp
+++ b/dom/ipc/ProcessHangMonitor.cpp
@@ -17,16 +17,17 @@
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/dom/TabChild.h"
 #include "mozilla/dom/TabParent.h"
 #include "mozilla/ipc/TaskFactory.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/plugins/PluginBridge.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Unused.h"
+#include "mozilla/WeakPtr.h"
 
 #include "nsIFrameLoader.h"
 #include "nsIHangReport.h"
 #include "nsITabParent.h"
 #include "nsPluginHost.h"
 #include "nsThreadUtils.h"
 #ifdef MOZ_CRASHREPORTER
 #include "nsExceptionHandler.h"
@@ -203,21 +204,24 @@ private:
   HangMonitorParent* mActor;
   ContentParent* mContentParent;
   HangData mHangData;
   nsAutoString mDumpId;
 };
 
 class HangMonitorParent
   : public PProcessHangMonitorParent
+  , public SupportsWeakPtr<HangMonitorParent>
 {
 public:
   explicit HangMonitorParent(ProcessHangMonitor* aMonitor);
   ~HangMonitorParent() override;
 
+  MOZ_DECLARE_WEAKREFERENCE_TYPENAME(HangMonitorParent)
+
   void Bind(Endpoint<PProcessHangMonitorParent>&& aEndpoint);
 
   mozilla::ipc::IPCResult RecvHangEvidence(const HangData& aHangData) override;
   mozilla::ipc::IPCResult RecvClearHang() override;
 
   void ActorDestroy(ActorDestroyReason aWhy) override;
 
   void SetProcess(HangMonitoredProcess* aProcess) { mProcess = aProcess; }
@@ -688,21 +692,29 @@ HangMonitorParent::SendHangNotification(
   // chrome process, main thread
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
 
   if ((aHangData.type() == HangData::TPluginHangData) && aTakeMinidump) {
     // We've been handed a partial minidump; complete it with plugin and
     // content process dumps.
     const PluginHangData& phd = aHangData.get_PluginHangData();
 
+    WeakPtr<HangMonitorParent> self = this;
     std::function<void(nsString)> callback =
-      [this, aHangData](nsString aResult) {
-        this->UpdateMinidump(aHangData.get_PluginHangData().pluginId(),
+      [self, aHangData](nsString aResult) {
+        MOZ_RELEASE_ASSERT(NS_IsMainThread());
+
+        if (!self) {
+          // Don't report hang since the process has already shut down.
+          return;
+        }
+
+        self->UpdateMinidump(aHangData.get_PluginHangData().pluginId(),
                        aResult);
-        this->OnTakeFullMinidumpComplete(aHangData, aResult);
+        self->OnTakeFullMinidumpComplete(aHangData, aResult);
       };
 
     plugins::TakeFullMinidump(phd.pluginId(),
                               phd.contentProcessId(),
                               aBrowserDumpId,
                               Move(callback),
                               true);
   } else {