Skip to content

fix: don't await for AppLaunching notification when CLI retries to attach to debugger #4047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ interface IiOSNotification extends NodeJS.EventEmitter {
}

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

Expand Down
4 changes: 4 additions & 0 deletions lib/definitions/debug.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ interface IDebugOptions {
* The sdk version of the emulator.
*/
sdk?: string;
/**
* 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.
*/
skipHandshake?: boolean;
}

/**
Expand Down
28 changes: 16 additions & 12 deletions lib/device-sockets/ios/socket-request-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,19 @@ export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
}
}

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

if (shouldBreak) {
if (debugOptions.debugBrk) {
await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getWaitForDebug(projectId));
}

// We need to send the ObserveNotification ReadyForAttach before we post the AttachRequest.
const readyForAttachSocket = await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getReadyForAttach(projectId), constants.IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE);
const readyForAttachPromise = this.$iOSNotificationService.awaitNotification(deviceIdentifier, +readyForAttachSocket, readyForAttachTimeout);

await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getAttachRequest(projectId, deviceIdentifier));
await readyForAttachPromise;
await this.executeAttachAvailable(deviceIdentifier, projectId, readyForAttachTimeout);
} catch (e) {
this.$logger.trace("Launch request error:");
this.$logger.trace(e);
this.$logger.trace("Launch request error: ", e);
this.$errors.failWithoutHelp("Error while waiting for response from NativeScript runtime.");
}
}
Expand All @@ -79,9 +74,18 @@ export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getAttachRequest(projectId, deviceIdentifier));
await readyForAttachPromise;
} catch (e) {
this.$logger.trace("Attach available error: ", e);
this.$errors.failWithoutHelp(`The application ${projectId} timed out when performing the socket handshake.`);
}
}

private async executeHandshake(deviceIdentifier: string, projectId: string, timeout: number): Promise<void> {
// This notification will be send only once by the runtime during application start.
// In case app is already running, we'll fail here as we'll not receive it.
const appLaunchingNotification = this.$iOSNotification.getAppLaunching(projectId);
const appLaunchingSocket = await this.$iOSNotificationService.postNotification(deviceIdentifier, appLaunchingNotification, constants.IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE);
await this.$iOSNotificationService.awaitNotification(deviceIdentifier, +appLaunchingSocket, timeout);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+appLaunchingSocket looks a bit strange, because this.$iOSNotificationService.postNotification should return a number according to the interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree, but I just moved this code and prefer not changing it.

}
}

$injector.register("iOSSocketRequestExecutor", IOSSocketRequestExecutor);
2 changes: 1 addition & 1 deletion lib/services/ios-debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
}

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

Expand Down
5 changes: 4 additions & 1 deletion lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
};
debugData.pathToAppPackage = this.$platformService.lastOutputPath(settings.platform, buildConfig, projectData, settings.outputPath);

return this.printDebugInformation(await this.$debugService.debug(debugData, settings.debugOptions));
const debugInfo = await this.$debugService.debug(debugData, settings.debugOptions);
const result = this.printDebugInformation(debugInfo);
return result;
}

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