Improve detecting if the updater is still alive

Rather than just testing if our connection is still alive (which is deceiving), we make a ping/pong request and see if we get a response back.
This commit is contained in:
Zorg committed 2016-07-15 16:48:26 -04:00
1 parent 64d740a761
commit ea6625024c
4 files changed
+25 -3

No files matched your search

+13 -1
View File
@@ -50,6 +50,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
@property (nonatomic) NSXPCConnection *activeConnection;
@property (nonatomic) id<SUInstallerCommunicationProtocol> communicator;
@property (nonatomic) StatusInfo *statusInfo;
@property (nonatomic) BOOL receivedUpdaterPong;
@property (nonatomic, strong) TerminationListener *terminationListener;
@@ -77,6 +78,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
@synthesize activeConnection = _activeConnection;
@synthesize communicator = _communicator;
@synthesize statusInfo = _statusInfo;
@synthesize receivedUpdaterPong = _receivedUpdaterPong;
@synthesize hostBundleIdentifier = _hostBundleIdentifier;
@synthesize allowsInteraction = _allowsInteraction;
@synthesize terminationListener = _terminationListener;
@@ -373,6 +375,8 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
}
});
});
} else if (identifier == SUUpdaterAlivePong) {
self.receivedUpdaterPong = YES;
}
}
@@ -522,6 +526,12 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
- (void)finishInstallationAfterHostTermination
{
[self.terminationListener startListeningWithCompletion:^{
// Ask the updater if it is still alive
// If they are, we will receive a pong response back
// Reset if we received a pong just to be on the safe side
self.receivedUpdaterPong = NO;
[self.communicator handleMessageWithIdentifier:SUUpdaterAlivePing data:[NSData data]];
// Launch our installer progress UI tool if only after a certain amount of time passes
__block NSRunningApplication *installerProgressRunningApplication = nil;
__block BOOL shouldLaunchInstallerProgress = YES;
@@ -538,7 +548,9 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SUDisplayProgressTimeDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// Make sure we're still eligible for showing the installer progress
// Also if the updater process is still alive, showing the progress should not be our duty
if (shouldLaunchInstallerProgress && self.communicator == nil) {
// if the communicator object is nil, the updater definitely isn't alive. However, if it is not nil,
// this does not necessarily mean the updater is alive, so we should also check if we got a recent response back from the updater
if (shouldLaunchInstallerProgress && (!self.receivedUpdaterPong || self.communicator == nil)) {
NSError *launchError = nil;
NSArray *arguments = @[self.host.bundlePath];
+4 -2
View File
@@ -25,14 +25,16 @@ typedef NS_ENUM(int32_t, SUInstallerMessageType)
SUInstallationStartedStage1 = 5,
SUInstallationFinishedStage1 = 6,
SUInstallationFinishedStage2 = 7,
SUInstallationFinishedStage3 = 8
SUInstallationFinishedStage3 = 8,
SUUpdaterAlivePing = 9
};
typedef NS_ENUM(int32_t, SUUpdaterMessageType)
{
SUInstallationData = 0,
SUSentUpdateAppcastItemData = 1,
SUResumeInstallationToStage2 = 2
SUResumeInstallationToStage2 = 2,
SUUpdaterAlivePong = 3
};
BOOL SUInstallerMessageTypeIsLegal(SUInstallerMessageType oldMessageType, SUInstallerMessageType newMessageType);
+5
View File
@@ -40,6 +40,11 @@ BOOL SUInstallerMessageTypeIsLegal(SUInstallerMessageType oldMessageType, SUInst
case SUInstallationFinishedStage3:
legal = (oldMessageType == SUInstallationFinishedStage2);
break;
case SUUpdaterAlivePing:
// Having this state being dependent on other installation states would make the complicate our logic
// So just always allow this type of message
legal = YES;
break;
}
return legal;
}
+3
View File
@@ -301,6 +301,9 @@
[self.delegate installerDidFinishInstallation];
[self.delegate installerIsRequestingAbortInstallWithError:nil];
} else if (identifier == SUUpdaterAlivePing) {
// Don't update the current stage; a ping request has no effect on that.
[self.installerConnection handleMessageWithIdentifier:SUUpdaterAlivePong data:[NSData data]];
}
}