Bug 1354200 - Exit instead of MOZ_CRASH on channel error in child process. r=jld, a=jcristau
authorJames Willcox <snorp@snorp.net>
Thu, 10 Jan 2019 22:45:44 +0000
changeset 506641 58340264bdac2c86845f2cb2d29877016e155c6d
parent 506640 f169ecb08260930d1dabf3b51533fea2822c6066
child 506642 5eeab947d0ff48e6340bbc6bedbb0f1ec774c707
push id10497
push userryanvm@gmail.com
push dateSat, 12 Jan 2019 18:08:31 +0000
treeherdermozilla-beta@c0445e5ce388 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjld, jcristau
bugs1354200
milestone65.0
Bug 1354200 - Exit instead of MOZ_CRASH on channel error in child process. r=jld, a=jcristau Android mercilessly kills the parent in low memory situations, and we don't want that to trigger a crash when the child is abruptly disconnected. Differential Revision: https://phabricator.services.mozilla.com/D16234
ipc/glue/MessageChannel.cpp
--- a/ipc/glue/MessageChannel.cpp
+++ b/ipc/glue/MessageChannel.cpp
@@ -5,16 +5,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ipc/MessageChannel.h"
 
 #include "mozilla/Assertions.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/dom/ScriptSettings.h"
+#include "mozilla/ipc/ProcessChild.h"
 #include "mozilla/ipc/ProtocolUtils.h"
 #include "mozilla/Logging.h"
 #include "mozilla/Move.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/ScopeExit.h"
 #include "mozilla/Sprintf.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/TimeStamp.h"
@@ -2519,17 +2520,26 @@ void MessageChannel::OnChannelErrorFromL
   IPC_LOG("OnChannelErrorFromLink");
 
   if (InterruptStackDepth() > 0) NotifyWorkerThread();
 
   if (AwaitingSyncReply() || AwaitingIncomingMessage()) NotifyWorkerThread();
 
   if (ChannelClosing != mChannelState) {
     if (mAbortOnError) {
-      MOZ_CRASH("Aborting on channel error.");
+      // mAbortOnError is set by main actors (e.g., ContentChild) to ensure
+      // that the process terminates even if normal shutdown is prevented.
+      // A MOZ_CRASH() here is not helpful because crash reporting relies
+      // on the parent process which we know is dead or otherwise unusable.
+      //
+      // Additionally, the parent process can (and often is) killed on Android
+      // when apps are backgrounded. We don't need to report a crash for
+      // normal behavior in that case.
+      printf_stderr("Exiting due to channel error.\n");
+      ProcessChild::QuickExit();
     }
     mChannelState = ChannelError;
     mMonitor->Notify();
   }
 
   PostErrorNotifyTask();
 }