From 8bb83ab05d68453630962137efe2971a7dab8e9b Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Tue, 23 Jan 2018 11:40:37 +0100 Subject: [PATCH] Bug 1351655 - Log which SharedThreadPools are not yet destroyed on shutdown-threads. r=froydnj We risk a shutdown hang without any clues if a dangling reference somewhere keeps a SharedThreadPool alive past xpcom-shutdown-threads. This because xpcom-shutdown-threads waits for all SharedThreadPool to be destroyed before advancing shutdown further. nsCycleCollector::Shutdown comes after xpcom-shutdown-threads so it is possible that a reference-cycle unexpectedly keeps a SharedThreadPool alive and blocks shutdown indefinitely. This patch attempts to help diagnose future cases like this by printing which SharedThreadPools we are going to wait for to stderr. MozReview-Commit-ID: CwTApYUMikA --HG-- extra : rebase_source : f29d04508cf492c82d65f324d7b1990849a0da13 --- xpcom/threads/SharedThreadPool.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/xpcom/threads/SharedThreadPool.cpp b/xpcom/threads/SharedThreadPool.cpp index 39678eb89bac..1927717079d5 100644 --- a/xpcom/threads/SharedThreadPool.cpp +++ b/xpcom/threads/SharedThreadPool.cpp @@ -47,6 +47,19 @@ SharedThreadPoolShutdownObserver::Observe(nsISupports* aSubject, const char *aTo const char16_t *aData) { MOZ_RELEASE_ASSERT(!strcmp(aTopic, "xpcom-shutdown-threads")); +#ifdef EARLY_BETA_OR_EARLIER + { + ReentrantMonitorAutoEnter mon(*sMonitor); + if (!sPools->Iter().Done()) { + nsAutoCString str; + for (auto i = sPools->Iter(); !i.Done(); i.Next()) { + str.AppendPrintf("\"%s\" ", nsAutoCString(i.Key()).get()); + } + printf_stderr("SharedThreadPool in xpcom-shutdown-threads. Waiting for " + "pools %s\n", str.get()); + } + } +#endif SharedThreadPool::SpinUntilEmpty(); sMonitor = nullptr; sPools = nullptr;