Bug 1286490: Handle IPC timeout exceptions during elevated updates on OSX. r=mstange a=lizzard
authorStephen A Pohl <spohl.mozilla.bugs@gmail.com>
Tue, 30 Aug 2016 10:09:50 -0700
changeset 342537 33fa756e769e1548b8f81aee313843eca0de09cf
parent 342536 6fa85d08812d106a9a23aa05f8ff08e0bd2aae15
child 342538 057ddf18f231f38a3bd7139c487cad958fb9f88b
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, lizzard
bugs1286490
milestone49.0
Bug 1286490: Handle IPC timeout exceptions during elevated updates on OSX. r=mstange a=lizzard
toolkit/mozapps/update/updater/launchchild_osx.mm
toolkit/xre/MacLaunchHelper.mm
--- a/toolkit/mozapps/update/updater/launchchild_osx.mm
+++ b/toolkit/mozapps/update/updater/launchchild_osx.mm
@@ -103,40 +103,45 @@ LaunchMacPostProcess(const char* aAppBun
   [task release];
 }
 
 id ConnectToUpdateServer()
 {
   MacAutoreleasePool pool;
 
   id updateServer = nil;
-  @try {
-    BOOL isConnected = NO;
-    int currTry = 0;
-    const int numRetries = 10; // Number of IPC connection retries before
-                               // giving up.
-    while (!isConnected && currTry < numRetries) {
+  BOOL isConnected = NO;
+  int currTry = 0;
+  const int numRetries = 10; // Number of IPC connection retries before
+                             // giving up.
+  while (!isConnected && currTry < numRetries) {
+    @try {
       updateServer = (id)[NSConnection
         rootProxyForConnectionWithRegisteredName:
           @"org.mozilla.updater.server"
         host:nil
         usingNameServer:[NSSocketPortNameServer sharedInstance]];
       if (!updateServer ||
           ![updateServer respondsToSelector:@selector(abort)] ||
           ![updateServer respondsToSelector:@selector(getArguments)] ||
           ![updateServer respondsToSelector:@selector(shutdown)]) {
         NSLog(@"Server doesn't exist or doesn't provide correct selectors.");
         sleep(1); // Wait 1 second.
         currTry++;
       } else {
         isConnected = YES;
       }
+    } @catch (NSException* e) {
+      NSLog(@"Encountered exception, retrying: %@: %@", e.name, e.reason);
+      sleep(1); // Wait 1 second.
+      currTry++;
     }
-  } @catch (NSException* e) {
-    // Ignore exceptions.
+  }
+  if (!isConnected) {
+    NSLog(@"Failed to connect to update server after several retries.");
     return nil;
   }
   return updateServer;
 }
 
 void CleanupElevatedMacUpdate(bool aFailureOccurred)
 {
   MacAutoreleasePool pool;
--- a/toolkit/xre/MacLaunchHelper.mm
+++ b/toolkit/xre/MacLaunchHelper.mm
@@ -144,37 +144,39 @@ BOOL InstallPrivilegedHelper()
   return result;
 }
 
 void AbortElevatedUpdate()
 {
   mozilla::MacAutoreleasePool pool;
 
   id updateServer = nil;
-  @try {
-    int currTry = 0;
-    const int numRetries = 10; // Number of IPC connection retries before
-                               // giving up.
-    while (currTry < numRetries) {
+  int currTry = 0;
+  const int numRetries = 10; // Number of IPC connection retries before
+                             // giving up.
+  while (currTry < numRetries) {
+    @try {
       updateServer = (id)[NSConnection
         rootProxyForConnectionWithRegisteredName:
           @"org.mozilla.updater.server"
         host:nil
         usingNameServer:[NSSocketPortNameServer sharedInstance]];
       if (updateServer &&
           [updateServer respondsToSelector:@selector(abort)]) {
         [updateServer performSelector:@selector(abort)];
         return;
       }
       NSLog(@"Server doesn't exist or doesn't provide correct selectors.");
       sleep(1); // Wait 1 second.
       currTry++;
+    } @catch (NSException* e) {
+      NSLog(@"Encountered exception, retrying: %@: %@", e.name, e.reason);
+      sleep(1); // Wait 1 second.
+      currTry++;
     }
-  } @catch (NSException* e) {
-    // Ignore exceptions.
   }
   NSLog(@"Unable to clean up updater.");
 }
 
 bool LaunchElevatedUpdate(int argc, char** argv, uint32_t aRestartType,
                           pid_t* pid)
 {
   LaunchChildMac(argc, argv, aRestartType, pid);