From c6258947616ab319ce1e78ebdd9a46f7ea739fe1 Mon Sep 17 00:00:00 2001 From: Julian Pscheid Date: Mon, 23 Mar 2026 05:57:35 -0700 Subject: [PATCH] Fix crash in clearDownloadedUpdate due to race condition of receiving delta update failure before probe status (#2863) Fix: call completionHandler before probe to prevent race with installer messages sendInstallationData kicks off the installer process, but completionHandler was deferred until the probe callback fired. Installer messages like SPUExtractionStarted could arrive on the main queue in the gap, triggering installerDidStartExtracting -> clearDownloadedUpdate before the caller set _downloadedUpdateForRemoval. A subsequent clearDownloadedUpdate (e.g. from installerDidFailToApplyDeltaUpdate) then found both ivars nil and hit the assertion. The probe result is only logged, so completing before the probe is safe. --- Sparkle/SPUCoreBasedUpdateDriver.m | 10 +++++++--- Sparkle/SPUInstallerDriver.m | 14 +++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Sparkle/SPUCoreBasedUpdateDriver.m b/Sparkle/SPUCoreBasedUpdateDriver.m index 34c6f06a..563a136a 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.m +++ b/Sparkle/SPUCoreBasedUpdateDriver.m @@ -198,9 +198,13 @@ - (void)clearDownloadedUpdate { id downloadedUpdateObject = (_resumableUpdate != nil) ? _resumableUpdate : _downloadedUpdateForRemoval; - assert(downloadedUpdateObject != nil); - - if (downloadedUpdateObject != nil && [downloadedUpdateObject isKindOfClass:[SPUDownloadedUpdate class]]) { + + if (downloadedUpdateObject == nil) { + SULog(SULogLevelError, @"Warning: clearDownloadedUpdate called but no downloaded update is tracked"); + return; + } + + if ([downloadedUpdateObject isKindOfClass:[SPUDownloadedUpdate class]]) { if (_downloadDriver == nil) { _downloadDriver = [[SPUDownloadDriver alloc] initWithHost:_host]; } diff --git a/Sparkle/SPUInstallerDriver.m b/Sparkle/SPUInstallerDriver.m index 323240f7..d780ee3b 100644 --- a/Sparkle/SPUInstallerDriver.m +++ b/Sparkle/SPUInstallerDriver.m @@ -487,18 +487,22 @@ self->_systemDomain = systemDomain; [self setUpConnection]; [self sendInstallationData]; - + + // Complete immediately so the caller can set up state (e.g., _downloadedUpdateForRemoval) + // before installer messages arrive on the main queue. + // Previously, completionHandler was called inside the probe callback, which meant + // installer messages (SPUExtractionStarted, SPUArchiveExtractionFailed) could be + // processed before the completion handler fired, leaving _downloadedUpdateForRemoval + // unset and causing an assertion crash in clearDownloadedUpdate. + completionHandler(nil); + // Send a probe/ping to the status service, which should boost/prioritize its startup if (hostBundleIdentifier != nil) { [SPUProbeInstallStatus probeInstallerInProgressForHostBundleIdentifier:hostBundleIdentifier completion:^(BOOL stausServiceIsRunning) { if (!stausServiceIsRunning) { SULog(SULogLevelError, @"Error: failed to probe status service for %@ from the framework", hostBundleIdentifier); } - - completionHandler(nil); }]; - } else { - completionHandler(nil); } break;