From abc14ae9f45e644ec19f24c240d9d0bdaebf5b59 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Wed, 19 Apr 2017 15:03:26 +0300 Subject: [PATCH] Fix debug on iOS simulator with watch During `tns debug ios`, in case you make changes, the application must be restarted and the debugger must attached again. However, in many cases we kill the old lldb process and immediately try to start the new one. The childProcess.kill operation finishes, but lldb process does not die immedietely. So in some occasions, the attach of new debugger fails. This leads to multiple errors - you cannot start this application on simulator anymore, you cannot exit CLI's process with `Ctrl + C`, etc. Fix this by attaching to "close" event of the processes and waiting for them to be really finish their execution. --- lib/services/ios-debug-service.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/services/ios-debug-service.ts b/lib/services/ios-debug-service.ts index 22b01dffaf..26105413af 100644 --- a/lib/services/ios-debug-service.ts +++ b/lib/services/ios-debug-service.ts @@ -78,20 +78,31 @@ class IOSDebugService extends DebugServiceBase implements IPlatformDebugService } _.forEach(this._sockets, socket => socket.destroy()); + this._sockets = []; if (this._lldbProcess) { this._lldbProcess.stdin.write("process detach\n"); - this._lldbProcess.kill(); + + await this.killProcess(this._lldbProcess); this._lldbProcess = undefined; } if (this._childProcess) { - this._childProcess.kill(); + await this.killProcess(this._childProcess); this._childProcess = undefined; } } + private async killProcess(childProcess: ChildProcess): Promise { + if (childProcess) { + return new Promise((resolve, reject) => { + childProcess.on("close", resolve); + childProcess.kill(); + }); + } + } + private async emulatorDebugBrk(debugData: IDebugData, debugOptions: IDebugOptions): Promise { let args = debugOptions.debugBrk ? "--nativescript-debug-brk" : "--nativescript-debug-start"; let child_process = await this.$iOSEmulatorServices.runApplicationOnEmulator(debugData.pathToAppPackage, {