Bug 1507947 - Be more careful when unbinding child process services. r=geckoview-reviewers,esawin, a=RyanVM
authorJames Willcox <snorp@snorp.net>
Wed, 12 Dec 2018 14:54:03 +0000
changeset 508992 d5f982689c717bba98621154f5dde808319eaa91
parent 508991 eed9d1166b691a3abc8e8214badbc9e40150b1c7
child 508993 d9d17041ca841fc9b80dc40eb926e376fd58a903
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, esawin, RyanVM
bugs1507947
milestone65.0
Bug 1507947 - Be more careful when unbinding child process services. r=geckoview-reviewers,esawin, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D14065
mobile/android/geckoview/src/main/java/org/mozilla/gecko/process/GeckoProcessManager.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/process/GeckoProcessManager.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/process/GeckoProcessManager.java
@@ -89,27 +89,35 @@ public final class GeckoProcessManager e
             if (context.bindService(intent, this, Context.BIND_AUTO_CREATE)) {
                 waitForChildLocked();
                 if (mChild != null) {
                     return mChild;
                 }
             }
 
             Log.e(LOGTAG, "Cannot connect to process " + mType);
-            context.unbindService(this);
+            unbind();
             return null;
         }
 
         public synchronized void unbind() {
+            // This could end up using IPC, so do it before we unbind.
+            final int pid = getPid();
+
             if (mChild != null) {
                 final Context context = GeckoAppShell.getApplicationContext();
-                context.unbindService(this);
+                try {
+                    context.unbindService(this);
+                } catch (IllegalArgumentException e) {
+                    mChild = null;
+                    mPid = 0;
+                    return;
+                }
             }
 
-            final int pid = getPid();
             if (pid != 0) {
                 Process.killProcess(pid);
                 waitForChildLocked();
             }
         }
 
         private void waitForChildLocked() {
             ThreadUtils.assertNotOnUiThread();
@@ -147,17 +155,21 @@ public final class GeckoProcessManager e
         }
 
         @Override
         public synchronized void binderDied() {
             Log.i(LOGTAG, "Binder died for " + mType);
             if (mChild != null) {
                 mChild = null;
                 mPid = 0;
-                GeckoAppShell.getApplicationContext().unbindService(this);
+
+                try {
+                    GeckoAppShell.getApplicationContext().unbindService(this);
+                } catch (IllegalArgumentException e) {
+                }
             }
         }
     }
 
     private final SimpleArrayMap<String, ChildConnection> mConnections;
 
     private GeckoProcessManager() {
         mConnections = new SimpleArrayMap<String, ChildConnection>();