Bug 704030 - Make the "all connections closed" check available on non debug builds. r=vladan.
authorRafael Ávila de Espíndola <respindola@mozilla.org>
Mon, 11 Feb 2013 12:05:59 -0500
changeset 131407 50df17d70386a66712e708873de7cdea130b6410
parent 131406 0d714dcba97926e367d655d152568dc132997fe8
child 131408 1b725f0b2e833916e0d21615b6f7fac334f850cc
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvladan
bugs704030
milestone21.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 704030 - Make the "all connections closed" check available on non debug builds. r=vladan.
storage/src/mozStorageService.cpp
toolkit/xre/nsAppRunner.cpp
xpcom/build/mozPoisonWrite.h
--- a/storage/src/mozStorageService.cpp
+++ b/storage/src/mozStorageService.cpp
@@ -17,16 +17,17 @@
 #include "nsThreadUtils.h"
 #include "mozStoragePrivateHelpers.h"
 #include "nsILocale.h"
 #include "nsILocaleService.h"
 #include "nsIXPConnect.h"
 #include "nsIObserverService.h"
 #include "mozilla/Services.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/mozPoisonWrite.h"
 
 #include "sqlite3.h"
 
 #ifdef SQLITE_OS_WIN
 // "windows.h" was included and it can #define lots of things we care about...
 #undef CompareString
 #endif
 
@@ -816,22 +817,24 @@ Service::Observe(nsISupports *, const ch
         }
       }
       if (anyOpen) {
         nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
         NS_ProcessNextEvent(thread);
       }
     } while (anyOpen);
 
-#ifdef DEBUG
-    nsTArray<nsRefPtr<Connection> > connections;
-    getConnections(connections);
-    for (uint32_t i = 0, n = connections.Length(); i < n; i++) {
-      MOZ_ASSERT(!connections[i]->ConnectionReady());
+    if (ShutdownChecks == SCM_CRASH) {
+      nsTArray<nsRefPtr<Connection> > connections;
+      getConnections(connections);
+      for (uint32_t i = 0, n = connections.Length(); i < n; i++) {
+        if (connections[i]->ConnectionReady()) {
+          MOZ_CRASH();
+        }
+      }
     }
-#endif
   }
 
   return NS_OK;
 }
 
 } // namespace storage
 } // namespace mozilla
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -3209,30 +3209,69 @@ XREMain::XRE_mainInit(const nsXREAppData
     }
     *aExitFlag = true;
     return 0;
   }
 
   return 0;
 }
 
+namespace mozilla {
+  ShutdownChecksMode ShutdownChecks = SCM_NOTHING;
+}
+
+static void SetShutdownChecks() {
+  // Set default first. On debug builds we crash. On nightly and local
+  // builds we record. Nightlies will then send the info via telemetry,
+  // but it is usefull to have the data in about:telemetry in local builds
+  // too.
+
+#ifdef DEBUG
+  ShutdownChecks = SCM_CRASH;
+#else
+  const char* releaseChannel = NS_STRINGIFY(MOZ_UPDATE_CHANNEL);
+  if (strcmp(releaseChannel, "nightly") == 0 ||
+      strcmp(releaseChannel, "default") == 0) {
+    ShutdownChecks = SCM_RECORD;
+  } else {
+    ShutdownChecks = SCM_NOTHING;
+  }
+#endif
+
+  // We let an environment variable override the default so that addons
+  // authors can use it for debugging shutdown with released firefox versions.
+  const char* mozShutdownChecksEnv = PR_GetEnv("MOZ_SHUTDOWN_CHECKS");
+  if (mozShutdownChecksEnv) {
+    if (strcmp(mozShutdownChecksEnv, "crash") == 0) {
+      ShutdownChecks = SCM_CRASH;
+    } else if (strcmp(mozShutdownChecksEnv, "record") == 0) {
+      ShutdownChecks = SCM_RECORD;
+    } else if (strcmp(mozShutdownChecksEnv, "nothing") == 0) {
+      ShutdownChecks = SCM_NOTHING;
+    }
+  }
+
+}
+
 /*
  * XRE_mainStartup - Initializes the profile and various other services.
  * Main() will exit early if either return value != 0 or if aExitFlag is
  * true.
  */
 int
 XREMain::XRE_mainStartup(bool* aExitFlag)
 {
   nsresult rv;
 
   if (!aExitFlag)
     return 1;
   *aExitFlag = false;
 
+  SetShutdownChecks();
+
 #if defined(MOZ_WIDGET_GTK) || defined(MOZ_ENABLE_XREMOTE)
   // Stash DESKTOP_STARTUP_ID in malloc'ed memory because gtk_init will clear it.
 #define HAVE_DESKTOP_STARTUP_ID
   const char* desktopStartupIDEnv = PR_GetEnv("DESKTOP_STARTUP_ID");
   if (desktopStartupIDEnv) {
     mDesktopStartupID.Assign(desktopStartupIDEnv);
   }
 #endif
--- a/xpcom/build/mozPoisonWrite.h
+++ b/xpcom/build/mozPoisonWrite.h
@@ -14,15 +14,22 @@ MOZ_BEGIN_EXTERN_C
   void MozillaRegisterDebugFD(int fd);
   void MozillaRegisterDebugFILE(FILE *f);
   void MozillaUnRegisterDebugFD(int fd);
   void MozillaUnRegisterDebugFILE(FILE *f);
 MOZ_END_EXTERN_C
 
 #ifdef __cplusplus
 namespace mozilla {
+enum ShutdownChecksMode {
+  SCM_CRASH,
+  SCM_RECORD,
+  SCM_NOTHING
+};
+extern ShutdownChecksMode ShutdownChecks;
+
 void PoisonWrite();
 void DisableWritePoisoning();
 void EnableWritePoisoning();
 }
 #endif
 
 #endif