Skip to content

Commit

Permalink
vm(qemu): fix stuck on busy when qemu fails to start
Browse files Browse the repository at this point in the history
  • Loading branch information
osy committed Mar 1, 2022
1 parent f55a4a8 commit 7a2c0a6
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Managers/UTMQemuVirtualMachine.m
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,21 @@ - (void)_vmStartWithCompletion:(void (^)(NSError * _Nullable))completion {
}
// start QEMU (this can be in parallel with QMP connect below)
__weak typeof(self) weakSelf = self;
__block NSError *qemuStartError = nil;
[self.system startWithCompletion:^(BOOL success, NSString *msg){
typeof(self) _self = weakSelf;
if (!_self) {
return; // outlived class
}
if (!success) {
dispatch_async(dispatch_get_main_queue(), ^{
[_self.delegate virtualMachine:_self didErrorWithMessage:msg];
});
qemuStartError = [_self errorWithMessage:msg];
if (_self.qemu.isConnected) { // we are NOT in vmStart, so pass error to delegate
dispatch_async(dispatch_get_main_queue(), ^{
[_self.delegate virtualMachine:_self didErrorWithMessage:msg];
});
}
}
[_self.qemu cancelConnectRetry]; // if we ARE in vmStart, this lets it progress
dispatch_semaphore_signal(_self.qemuDidExitEvent);
[_self vmStopForce:YES completion:^(NSError *error){}];
}];
Expand All @@ -341,10 +346,15 @@ - (void)_vmStartWithCompletion:(void (^)(NSError * _Nullable))completion {
completion([self errorGeneric]);
return;
}
if (qemuStartError) {
completion(qemuStartError);
return;
}
if (callbackError) {
completion(callbackError);
return;
}
assert(self.qemu.isConnected);
// wait for QMP to connect
if (dispatch_semaphore_wait(self.qemuDidConnectEvent, dispatch_time(DISPATCH_TIME_NOW, kStopTimeout)) != 0) {
UTMLog(@"Timed out waiting for QMP connect event");
Expand Down Expand Up @@ -389,7 +399,6 @@ - (void)_vmStartWithCompletion:(void (^)(NSError * _Nullable))completion {
completion(err);
return;
}
assert(self.qemu.isConnected);
assert(self.ioService.isConnected);
if (self.viewState.hasSaveState) {
[self _vmDeleteStateWithCompletion:^(NSError *error){
Expand Down

0 comments on commit 7a2c0a6

Please sign in to comment.