Bug 1138282 - Extend telemetry for large number of SERVICE_STILL_APPLYING_ON_FAILURE errors. r=bbondy, a=lhenry
authorRobert Strong <robert.bugzilla@gmail.com>
Tue, 14 Apr 2015 15:32:18 -0700
changeset 267050 d4d33c5946d04b7e9ce5c8b64efb567f8e497d60
parent 267049 8d6fa774aa8ddaef0a2c8b5d8d36de6f9c3af2e3
child 267051 7f06e1d0445d1958be278b7daf5a0217c22ab2e8
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbondy, lhenry
bugs1138282
milestone39.0a2
Bug 1138282 - Extend telemetry for large number of SERVICE_STILL_APPLYING_ON_FAILURE errors. r=bbondy, a=lhenry
toolkit/components/maintenanceservice/workmonitor.cpp
toolkit/mozapps/update/common/errors.h
toolkit/mozapps/update/nsUpdateService.js
--- a/toolkit/components/maintenanceservice/workmonitor.cpp
+++ b/toolkit/components/maintenanceservice/workmonitor.cpp
@@ -228,63 +228,70 @@ StartUpdateProcess(int argc,
   // Search in updater.cpp for more info on MOZ_USING_SERVICE.
   putenv(const_cast<char*>("MOZ_USING_SERVICE=1"));
   LOG(("Starting service with cmdline: %ls", cmdLine));
   processStarted = CreateProcessW(argv[0], cmdLine,
                                   nullptr, nullptr, FALSE,
                                   CREATE_DEFAULT_ERROR_MODE,
                                   nullptr,
                                   nullptr, &si, &pi);
-  // Empty value on putenv is how you remove an env variable in Windows
-  putenv(const_cast<char*>("MOZ_USING_SERVICE="));
 
   BOOL updateWasSuccessful = FALSE;
   if (processStarted) {
+    BOOL processTerminated = FALSE;
+    BOOL noProcessExitCode = FALSE;
     // Wait for the updater process to finish
     LOG(("Process was started... waiting on result."));
     DWORD waitRes = WaitForSingleObject(pi.hProcess, TIME_TO_WAIT_ON_UPDATER);
     if (WAIT_TIMEOUT == waitRes) {
       // We waited a long period of time for updater.exe and it never finished
       // so kill it.
       TerminateProcess(pi.hProcess, 1);
+      processTerminated = TRUE;
     } else {
       // Check the return code of updater.exe to make sure we get 0
       DWORD returnCode;
       if (GetExitCodeProcess(pi.hProcess, &returnCode)) {
         LOG(("Process finished with return code %d.", returnCode));
         // updater returns 0 if successful.
         updateWasSuccessful = (returnCode == 0);
       } else {
         LOG_WARN(("Process finished but could not obtain return code."));
+        noProcessExitCode = TRUE;
       }
     }
     CloseHandle(pi.hProcess);
     CloseHandle(pi.hThread);
 
     // Check just in case updater.exe didn't change the status from
     // applying.  If this is the case we report an error.
     BOOL isApplying = FALSE;
     if (IsStatusApplying(argv[1], isApplying) && isApplying) {
       if (updateWasSuccessful) {
-        LOG(("update.status is still applying even know update "
-             " was successful."));
+        LOG(("update.status is still applying even though update was "
+             "successful."));
         if (!WriteStatusFailure(argv[1],
                                 SERVICE_STILL_APPLYING_ON_SUCCESS)) {
-          LOG_WARN(("Could not write update.status still applying on"
-                    " success error."));
+          LOG_WARN(("Could not write update.status still applying on "
+                    "success error."));
         }
         // Since we still had applying we know updater.exe didn't do its
         // job correctly.
         updateWasSuccessful = FALSE;
       } else {
         LOG_WARN(("update.status is still applying and update was not successful."));
-        if (!WriteStatusFailure(argv[1],
-                                SERVICE_STILL_APPLYING_ON_FAILURE)) {
-          LOG_WARN(("Could not write update.status still applying on"
-                    " success error."));
+        int failcode = SERVICE_STILL_APPLYING_ON_FAILURE;
+        if (noProcessExitCode) {
+          failcode = SERVICE_STILL_APPLYING_NO_EXIT_CODE;
+        } else if (processTerminated) {
+          failcode = SERVICE_STILL_APPLYING_TERMINATED;
+        }
+        if (!WriteStatusFailure(argv[1], failcode)) {
+          LOG_WARN(("Could not write update.status still applying on "
+                    "failure error."));
         }
       }
     }
   } else {
     DWORD lastError = GetLastError();
     LOG_WARN(("Could not create process as current user, "
               "updaterPath: %ls; cmdLine: %ls.  (%d)",
               argv[0], cmdLine, lastError));
@@ -316,16 +323,18 @@ StartUpdateProcess(int argc,
         if (!LaunchWinPostProcess(installDir, updateInfoDir, true, nullptr)) {
           LOG_WARN(("The post update process could not be launched."
                     " installDir: %ls, updateInfoDir: %ls",
                     installDir, updateInfoDir));
         }
       }
     }
   }
+  // Empty value on putenv is how you remove an env variable in Windows
+  putenv(const_cast<char*>("MOZ_USING_SERVICE="));
 
   free(cmdLine);
   return updateWasSuccessful;
 }
 
 /**
  * Processes a software update command
  *
--- a/toolkit/mozapps/update/common/errors.h
+++ b/toolkit/mozapps/update/common/errors.h
@@ -37,17 +37,17 @@
 #define CERT_LOAD_ERROR 17
 #define CERT_HANDLING_ERROR 18
 #define CERT_VERIFY_ERROR 19
 #define ARCHIVE_NOT_OPEN 20
 #define COULD_NOT_READ_PRODUCT_INFO_BLOCK_ERROR 21
 #define MAR_CHANNEL_MISMATCH_ERROR 22
 #define VERSION_DOWNGRADE_ERROR 23
 
-// Error codes 24-33 and 49 are for the Windows maintenance service.
+// Error codes 24-33 and 49-51 are for the Windows maintenance service.
 #define SERVICE_UPDATER_COULD_NOT_BE_STARTED 24
 #define SERVICE_NOT_ENOUGH_COMMAND_LINE_ARGS 25
 #define SERVICE_UPDATER_SIGN_ERROR 26
 #define SERVICE_UPDATER_COMPARE_ERROR 27
 #define SERVICE_UPDATER_IDENTITY_ERROR 28
 #define SERVICE_STILL_APPLYING_ON_SUCCESS 29
 #define SERVICE_STILL_APPLYING_ON_FAILURE 30
 #define SERVICE_UPDATER_NOT_FIXED_DRIVE 31
@@ -62,18 +62,20 @@
 #define UNEXPECTED_MAR_ERROR 40
 #define UNEXPECTED_BSPATCH_ERROR 41
 #define UNEXPECTED_FILE_OPERATION_ERROR 42
 #define FILESYSTEM_MOUNT_READWRITE_ERROR 43
 #define DELETE_ERROR_EXPECTED_DIR 46
 #define DELETE_ERROR_EXPECTED_FILE 47
 #define RENAME_ERROR_EXPECTED_FILE 48
 
-// Error codes 24-33 and 49 are for the Windows maintenance service.
+// Error codes 24-33 and 49-51 are for the Windows maintenance service.
 #define SERVICE_COULD_NOT_COPY_UPDATER 49
+#define SERVICE_STILL_APPLYING_TERMINATED 50
+#define SERVICE_STILL_APPLYING_NO_EXIT_CODE 51
 
 #define WRITE_ERROR_FILE_COPY 61
 #define WRITE_ERROR_DELETE_FILE 62
 #define WRITE_ERROR_OPEN_PATCH_FILE 63
 #define WRITE_ERROR_PATCH_FILE 64
 #define WRITE_ERROR_APPLY_DIR_PATH 65
 #define WRITE_ERROR_CALLBACK_PATH 66
 #define WRITE_ERROR_FILE_ACCESS_DENIED 67
--- a/toolkit/mozapps/update/nsUpdateService.js
+++ b/toolkit/mozapps/update/nsUpdateService.js
@@ -132,16 +132,18 @@ const SERVICE_STILL_APPLYING_ON_SUCCESS 
 const SERVICE_STILL_APPLYING_ON_FAILURE    = 30;
 const SERVICE_UPDATER_NOT_FIXED_DRIVE      = 31;
 const SERVICE_COULD_NOT_LOCK_UPDATER       = 32;
 const SERVICE_INSTALLDIR_ERROR             = 33;
 const WRITE_ERROR_ACCESS_DENIED            = 35;
 const WRITE_ERROR_CALLBACK_APP             = 37;
 const FILESYSTEM_MOUNT_READWRITE_ERROR     = 43;
 const SERVICE_COULD_NOT_COPY_UPDATER       = 49;
+const SERVICE_STILL_APPLYING_TERMINATED    = 50;
+const SERVICE_STILL_APPLYING_NO_EXIT_CODE  = 51;
 const WRITE_ERROR_FILE_COPY                = 61;
 const WRITE_ERROR_DELETE_FILE              = 62;
 const WRITE_ERROR_OPEN_PATCH_FILE          = 63;
 const WRITE_ERROR_PATCH_FILE               = 64;
 const WRITE_ERROR_APPLY_DIR_PATH           = 65;
 const WRITE_ERROR_CALLBACK_PATH            = 66;
 const WRITE_ERROR_FILE_ACCESS_DENIED       = 67;
 const WRITE_ERROR_DIR_ACCESS_DENIED        = 68;
@@ -169,17 +171,19 @@ const SERVICE_ERRORS = [SERVICE_UPDATER_
                         SERVICE_UPDATER_SIGN_ERROR,
                         SERVICE_UPDATER_COMPARE_ERROR,
                         SERVICE_UPDATER_IDENTITY_ERROR,
                         SERVICE_STILL_APPLYING_ON_SUCCESS,
                         SERVICE_STILL_APPLYING_ON_FAILURE,
                         SERVICE_UPDATER_NOT_FIXED_DRIVE,
                         SERVICE_COULD_NOT_LOCK_UPDATER,
                         SERVICE_INSTALLDIR_ERROR,
-                        SERVICE_COULD_NOT_COPY_UPDATER];
+                        SERVICE_COULD_NOT_COPY_UPDATER,
+                        SERVICE_STILL_APPLYING_TERMINATED,
+                        SERVICE_STILL_APPLYING_NO_EXIT_CODE];
 
 // Error codes 80 through 99 are reserved for nsUpdateService.js and are not
 // defined in common/errors.h
 const FOTA_GENERAL_ERROR                   = 80;
 const FOTA_UNKNOWN_ERROR                   = 81;
 const FOTA_FILE_OPERATION_ERROR            = 82;
 const FOTA_RECOVERY_ERROR                  = 83;
 // Staging failed and changed the state to pending