Skip to content

Commit 855eb87

Browse files
committed
fix: doesn't await for AppLaunching notification when CLI retries to attach to debugger
1 parent b9bfc68 commit 855eb87

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

lib/declarations.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ interface IiOSNotification extends NodeJS.EventEmitter {
709709
}
710710

711711
interface IiOSSocketRequestExecutor {
712-
executeLaunchRequest(deviceIdentifier: string, timeout: number, readyForAttachTimeout: number, projectId: string, shouldBreak?: boolean): Promise<void>;
712+
executeLaunchRequest(deviceIdentifier: string, timeout: number, readyForAttachTimeout: number, projectId: string, debugOptions: IDebugOptions): Promise<void>;
713713
executeAttachRequest(device: Mobile.IiOSDevice, timeout: number, projectId: string): Promise<void>;
714714
}
715715

lib/definitions/debug.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ interface IDebugOptions {
9595
* The sdk version of the emulator.
9696
*/
9797
sdk?: string;
98+
/**
99+
* Defines if the handshake(AppLaunching notification) between CLI and runtime should be executed. The handshake is not needed when CLI retries to attach to the debugger.
100+
*/
101+
skipHandshake?: boolean;
98102
}
99103

100104
/**

lib/device-sockets/ios/socket-request-executor.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,19 @@ export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
4848
}
4949
}
5050

51-
public async executeLaunchRequest(deviceIdentifier: string, timeout: number, readyForAttachTimeout: number, projectId: string, shouldBreak?: boolean): Promise<void> {
51+
public async executeLaunchRequest(deviceIdentifier: string, timeout: number, readyForAttachTimeout: number, projectId: string, debugOptions: IDebugOptions): Promise<void> {
5252
try {
53-
const appLaunchingSocket = await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getAppLaunching(projectId), constants.IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE);
54-
await this.$iOSNotificationService.awaitNotification(deviceIdentifier, +appLaunchingSocket, timeout);
53+
if (!debugOptions.skipHandshake) {
54+
await this.executeHandshake(deviceIdentifier, projectId, timeout);
55+
}
5556

56-
if (shouldBreak) {
57+
if (debugOptions.debugBrk) {
5758
await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getWaitForDebug(projectId));
5859
}
5960

60-
// We need to send the ObserveNotification ReadyForAttach before we post the AttachRequest.
61-
const readyForAttachSocket = await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getReadyForAttach(projectId), constants.IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE);
62-
const readyForAttachPromise = this.$iOSNotificationService.awaitNotification(deviceIdentifier, +readyForAttachSocket, readyForAttachTimeout);
63-
64-
await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getAttachRequest(projectId, deviceIdentifier));
65-
await readyForAttachPromise;
61+
await this.executeAttachAvailable(deviceIdentifier, projectId, readyForAttachTimeout);
6662
} catch (e) {
67-
this.$logger.trace("Launch request error:");
68-
this.$logger.trace(e);
63+
this.$logger.trace("Launch request error: ", e);
6964
this.$errors.failWithoutHelp("Error while waiting for response from NativeScript runtime.");
7065
}
7166
}
@@ -79,9 +74,18 @@ export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
7974
await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getAttachRequest(projectId, deviceIdentifier));
8075
await readyForAttachPromise;
8176
} catch (e) {
77+
this.$logger.trace("Attach available error: ", e);
8278
this.$errors.failWithoutHelp(`The application ${projectId} timed out when performing the socket handshake.`);
8379
}
8480
}
81+
82+
private async executeHandshake(deviceIdentifier: string, projectId: string, timeout: number): Promise<void> {
83+
// This notification will be send only once by the runtime during application start.
84+
// In case app is already running, we'll fail here as we'll not receive it.
85+
const appLaunchingNotification = this.$iOSNotification.getAppLaunching(projectId);
86+
const appLaunchingSocket = await this.$iOSNotificationService.postNotification(deviceIdentifier, appLaunchingNotification, constants.IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE);
87+
await this.$iOSNotificationService.awaitNotification(deviceIdentifier, +appLaunchingSocket, timeout);
88+
}
8589
}
8690

8791
$injector.register("iOSSocketRequestExecutor", IOSSocketRequestExecutor);

lib/services/ios-debug-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
182182
}
183183

184184
private async debugBrkCore(device: Mobile.IiOSDevice, debugData: IDebugData, debugOptions: IDebugOptions): Promise<string> {
185-
await this.$iOSSocketRequestExecutor.executeLaunchRequest(device.deviceInfo.identifier, AWAIT_NOTIFICATION_TIMEOUT_SECONDS, AWAIT_NOTIFICATION_TIMEOUT_SECONDS, debugData.applicationIdentifier, debugOptions.debugBrk);
185+
await this.$iOSSocketRequestExecutor.executeLaunchRequest(device.deviceInfo.identifier, AWAIT_NOTIFICATION_TIMEOUT_SECONDS, AWAIT_NOTIFICATION_TIMEOUT_SECONDS, debugData.applicationIdentifier, debugOptions);
186186
return this.wireDebuggerClient(debugData, debugOptions, device);
187187
}
188188

lib/services/livesync/livesync-service.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
224224
};
225225
debugData.pathToAppPackage = this.$platformService.lastOutputPath(settings.platform, buildConfig, projectData, settings.outputPath);
226226

227-
return this.printDebugInformation(await this.$debugService.debug(debugData, settings.debugOptions));
227+
const debugInfo = await this.$debugService.debug(debugData, settings.debugOptions);
228+
const result = this.printDebugInformation(debugInfo);
229+
return result;
228230
}
229231

230232
public printDebugInformation(debugInformation: IDebugInformation): IDebugInformation {
@@ -270,6 +272,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
270272
} catch (err) {
271273
this.$logger.trace("Couldn't attach debugger, will modify options and try again.", err);
272274
attachDebuggerOptions.debugOptions.start = false;
275+
attachDebuggerOptions.debugOptions.skipHandshake = true;
273276
try {
274277
debugInformation = await this.attachDebugger(attachDebuggerOptions);
275278
} catch (innerErr) {

0 commit comments

Comments
 (0)