diff --git a/lib/common b/lib/common index b73104ba99..b88415ac1c 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit b73104ba99a45c9c3fb05cbfb14ee9913f1aac4b +Subproject commit b88415ac1c04d356687ea900424477adfcefaa46 diff --git a/lib/services/android-debug-service.ts b/lib/services/android-debug-service.ts index 32c544a911..388198aa6d 100644 --- a/lib/services/android-debug-service.ts +++ b/lib/services/android-debug-service.ts @@ -24,7 +24,8 @@ class AndroidDebugService implements IDebugService { private $hostInfo: IHostInfo, private $errors: IErrors, private $opener: IOpener, - private $staticConfig: IStaticConfig) { } + private $staticConfig: IStaticConfig, + private $utils: IUtils) { } private get platform() { return "android"; } @@ -195,8 +196,8 @@ class AndroidDebugService implements IDebugService { private startAndGetPort(packageName: string): IFuture { return (() => { let port = -1; - let timeout = 60; - + let timeout = this.$utils.getParsedTimeout(60); + let packageDir = util.format(AndroidDebugService.PACKAGE_EXTERNAL_DIR_TEMPLATE, packageName); let envDebugInFullpath = packageDir + AndroidDebugService.ENV_DEBUG_IN_FILENAME; this.device.adb.executeShellCommand(`rm "${envDebugInFullpath}"`).wait(); diff --git a/lib/services/ios-debug-service.ts b/lib/services/ios-debug-service.ts index 4a7f0eefc1..e1451d82c0 100644 --- a/lib/services/ios-debug-service.ts +++ b/lib/services/ios-debug-service.ts @@ -60,6 +60,8 @@ function connectEventually(factory: () => net.Socket, handler: (socket: net.Sock } class IOSDebugService implements IDebugService { + private static TIMEOUT_SECONDS = 60; + constructor( private $platformService: IPlatformService, private $iOSEmulatorServices: Mobile.IEmulatorPlatformServices, @@ -73,16 +75,22 @@ class IOSDebugService implements IDebugService { private $injector: IInjector, private $npmInstallationManager: INpmInstallationManager, private $options: IOptions, - private $projectDataService: IProjectDataService) { } + private $projectDataService: IProjectDataService, + private $utils: IUtils) { } get platform(): string { return "ios"; } public debug(): IFuture { - if ((!this.$options.debugBrk && !this.$options.start) || (this.$options.debugBrk && this.$options.start)) { + if (this.$options.debugBrk && this.$options.start) { this.$errors.failWithoutHelp("Expected exactly one of the --debug-brk or --start options."); } + + if(!this.$options.debugBrk && !this.$options.start) { + this.$logger.warn("Neither --debug-brk nor --start option was specified. Defaulting to --debug-brk."); + this.$options.debugBrk = true; + } if (this.$options.emulator) { if (this.$options.debugBrk) { @@ -137,12 +145,14 @@ class IOSDebugService implements IDebugService { let npc = new iOSProxyServices.NotificationProxyClient(iosDevice, this.$injector); try { - awaitNotification(npc, notification.appLaunching(projectId), 60000).wait(); + let timeout = this.$utils.getMilliSecondsTimeout(IOSDebugService.TIMEOUT_SECONDS); + awaitNotification(npc, notification.appLaunching(projectId), timeout).wait(); process.nextTick(() => { npc.postNotificationAndAttachForData(notification.waitForDebug(projectId)); npc.postNotificationAndAttachForData(notification.attachRequest(projectId)); }); - awaitNotification(npc, notification.readyForAttach(projectId), 5000).wait(); + + awaitNotification(npc, notification.readyForAttach(projectId), this.getReadyForAttachTimeout(timeout)).wait(); } catch(e) { this.$logger.trace(`Timeout error: ${e}`); this.$errors.failWithoutHelp("Timeout waiting for NativeScript debugger."); @@ -163,11 +173,12 @@ class IOSDebugService implements IDebugService { let projectId = this.$projectData.projectId; let npc = new iOSProxyServices.NotificationProxyClient(iosDevice, this.$injector); + let timeout = this.getReadyForAttachTimeout(); let [alreadyConnected, readyForAttach, attachAvailable] = [ notification.alreadyConnected(projectId), notification.readyForAttach(projectId), notification.attachAvailable(projectId) - ].map((notification) => awaitNotification(npc, notification, 2000)); + ].map((notification) => awaitNotification(npc, notification, timeout)); npc.postNotificationAndAttachForData(notification.attachAvailabilityQuery(projectId)); @@ -183,7 +194,7 @@ class IOSDebugService implements IDebugService { this.$errors.failWithoutHelp("A debugger is already connected."); case attachAvailable: process.nextTick(() => npc.postNotificationAndAttachForData(notification.attachRequest(projectId))); - try { awaitNotification(npc, notification.readyForAttach(projectId), 2000).wait(); } + try { awaitNotification(npc, notification.readyForAttach(projectId), timeout).wait(); } catch (e) { this.$errors.failWithoutHelp(`The application ${projectId} timed out when performing the NativeScript debugger handshake.`); } @@ -244,6 +255,14 @@ class IOSDebugService implements IDebugService { return inspectorPath; }).future()(); } + + + private getReadyForAttachTimeout(timeoutInMilliseconds?: number): number { + let timeout = timeoutInMilliseconds || this.$utils.getMilliSecondsTimeout(IOSDebugService.TIMEOUT_SECONDS); + let readyForAttachTimeout = timeout / 10 ; + let defaultReadyForAttachTimeout = 5000; + return readyForAttachTimeout > defaultReadyForAttachTimeout ? readyForAttachTimeout : defaultReadyForAttachTimeout; + } } $injector.register("iOSDebugService", IOSDebugService); @@ -306,7 +325,7 @@ function awaitNotification(npc: iOSProxyServices.NotificationProxyClient, notifi let timeoutObject = setTimeout(() => { detachObserver(); - future.throw(new Error("Timeout receiving notification.")); + future.throw(new Error(`Timeout receiving ${notification} notification.`)); }, timeout); function notificationObserver(notification: string) {