Bug 1301339 - Annotate content shutdown hang due to nested event loop in RecvShutdown. r=billm draft
authorKan-Ru Chen <kanru@kanru.info>
Thu, 08 Sep 2016 17:23:57 +0800
changeset 412048 d10473df009a25b5ccfce8e27831a4d1dacf57f3
parent 411433 77940cbf0c2a9f52c209fbbde5b2e7d4c74a1501
child 530860 7215e744f6fd5a6472b7b727a6c44c5abf7ef33a
push id29033
push userbmo:kchen@mozilla.com
push dateFri, 09 Sep 2016 07:02:44 +0000
reviewersbillm
bugs1301339
milestone51.0a1
Bug 1301339 - Annotate content shutdown hang due to nested event loop in RecvShutdown. r=billm We currently allow nested event loop to delay ContentChild::RecvShutdown which in turn might cause content process shutdown hang. This patch attempts to annotate the crash report that a shutdown hang was after we have received RecvShutdown but never reach SendFinishShutdown or the hang happened before or after RecvShutdown. MozReview-Commit-ID: 8pGqwzLlYpK
dom/ipc/ContentChild.cpp
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -2978,16 +2978,20 @@ ContentChild::ForceKillTimerCallback(nsI
 
 bool
 ContentChild::RecvShutdown()
 {
   // If we receive the shutdown message from within a nested event loop, we want
   // to wait for that event loop to finish. Otherwise we could prematurely
   // terminate an "unload" or "pagehide" event handler (which might be doing a
   // sync XHR, for example).
+#if defined(MOZ_CRASHREPORTER)
+  CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("IPCShutdownState"),
+                                     NS_LITERAL_CSTRING("RecvShutdown"));
+#endif
   nsCOMPtr<nsIThread> thread;
   nsresult rv = NS_GetMainThread(getter_AddRefs(thread));
   if (NS_SUCCEEDED(rv) && thread) {
     RefPtr<nsThread> mainThread(thread.forget().downcast<nsThread>());
     if (mainThread->RecursionDepth() > 1) {
       // We're in a nested event loop. Let's delay for an arbitrary period of
       // time (100ms) in the hopes that the event loop will have finished by
       // then.
@@ -3025,16 +3029,20 @@ ContentChild::RecvShutdown()
   }
 #endif
 
   // Start a timer that will insure we quickly exit after a reasonable
   // period of time. Prevents shutdown hangs after our connection to the
   // parent closes.
   StartForceKillTimer();
 
+#if defined(MOZ_CRASHREPORTER)
+  CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("IPCShutdownState"),
+                                     NS_LITERAL_CSTRING("SendFinishShutdown"));
+#endif
   // Ignore errors here. If this fails, the parent will kill us after a
   // timeout.
   Unused << SendFinishShutdown();
   return true;
 }
 
 PBrowserOrId
 ContentChild::GetBrowserOrId(TabChild* aTabChild)