Skip to content

Commit 2af3615

Browse files
Fix debug on iOS simulator with watch (#2721)
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.
1 parent d992963 commit 2af3615

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/services/ios-debug-service.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,31 @@ class IOSDebugService extends DebugServiceBase implements IPlatformDebugService
7878
}
7979

8080
_.forEach(this._sockets, socket => socket.destroy());
81+
8182
this._sockets = [];
8283

8384
if (this._lldbProcess) {
8485
this._lldbProcess.stdin.write("process detach\n");
85-
this._lldbProcess.kill();
86+
87+
await this.killProcess(this._lldbProcess);
8688
this._lldbProcess = undefined;
8789
}
8890

8991
if (this._childProcess) {
90-
this._childProcess.kill();
92+
await this.killProcess(this._childProcess);
9193
this._childProcess = undefined;
9294
}
9395
}
9496

97+
private async killProcess(childProcess: ChildProcess): Promise<void> {
98+
if (childProcess) {
99+
return new Promise<void>((resolve, reject) => {
100+
childProcess.on("close", resolve);
101+
childProcess.kill();
102+
});
103+
}
104+
}
105+
95106
private async emulatorDebugBrk(debugData: IDebugData, debugOptions: IDebugOptions): Promise<string> {
96107
let args = debugOptions.debugBrk ? "--nativescript-debug-brk" : "--nativescript-debug-start";
97108
let child_process = await this.$iOSEmulatorServices.runApplicationOnEmulator(debugData.pathToAppPackage, {

0 commit comments

Comments
 (0)