Skip to content

Commit 7563704

Browse files
committed
Ensure the CLI process is killed when the client is dosconnected
1 parent 9dedd4a commit 7563704

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/debug-adapter/webKitDebugAdapter.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import * as os from 'os';
66
import * as fs from 'fs';
77
import * as path from 'path';
8+
import {ChildProcess} from 'child_process';
89
import {Handles, StoppedEvent, InitializedEvent, TerminatedEvent, OutputEvent} from 'vscode-debugadapter';
910
import {DebugProtocol} from 'vscode-debugprotocol';
1011
import {INSDebugConnection} from './connection/INSDebugConnection';
@@ -42,6 +43,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
4243
private _lastOutputEvent: OutputEvent;
4344
private _loggerFrontendHandler: LoggerHandler = args => this.fireEvent(new OutputEvent(`${args.message}\n`, args.type.toString()));
4445
private _request: DebugRequest;
46+
private _tnsProcess: ChildProcess;
4547

4648
public constructor() {
4749
this._variableHandles = new Handles<IScopeVarHandle>();
@@ -153,9 +155,12 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
153155
}
154156

155157
if (cliCommand.tnsProcess) {
158+
this._tnsProcess = cliCommand.tnsProcess;
156159
cliCommand.tnsProcess.stdout.on('data', data => { Services.logger().log(data.toString(), Tags.FrontendMessage); });
157160
cliCommand.tnsProcess.stderr.on('data', data => { Services.logger().error(data.toString(), Tags.FrontendMessage); });
158-
cliCommand.tnsProcess.on('close', (code, signal) => { Services.logger().error(`[NSDebugAdapter] The tns command finished its execution with code ${code}.`, Tags.FrontendMessage); });
161+
cliCommand.tnsProcess.on('close', (code, signal) => {
162+
Services.logger().error(`[NSDebugAdapter] The tns command finished its execution with code ${code}.`, Tags.FrontendMessage);
163+
});
159164
}
160165

161166
let promiseResolve = null;
@@ -191,7 +196,10 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
191196
connection.on('Console.messageRepeatCountUpdated', params => this.onMessageRepeatCountUpdated(params));
192197
connection.on('Inspector.detached', () => this.terminateSession());
193198
connection.on('close', () => this.terminateSession());
194-
connection.on('error', () => this.terminateSession());
199+
connection.on('error', (error) => {
200+
Services.logger().log(error.toString());
201+
this.terminateSession();
202+
});
195203
connection.on('connect', () => this.onConnected())
196204
this._webKitConnection = connection;
197205
return connection;
@@ -220,6 +228,11 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
220228
this.clearClientContext();
221229
this.clearTargetContext();
222230

231+
if (this._tnsProcess) {
232+
this._tnsProcess.kill('SIGQUIT');
233+
this._tnsProcess = null;
234+
}
235+
223236
if (this._webKitConnection) {
224237
Services.logger().log("Closing debug connection");
225238

@@ -356,7 +369,6 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
356369
.then(responses => ({ breakpoints: this._webkitBreakpointResponsesToODPBreakpoints(targetScriptUrl, responses, args.lines) }));
357370

358371
const inDebug = typeof (<any>global).v8debug === 'object';
359-
console.log("InDebug: " + inDebug);
360372
const setBreakpointsPTimeout = utils.promiseTimeout(setBreakpointsPFailOnError, /*timeoutMs*/inDebug ? 2000000 : 8000, 'Set breakpoints request timed out');
361373

362374
// Do just one setBreakpointsRequest at a time to avoid interleaving breakpoint removed/breakpoint added requests to Chrome.

src/debug-adapter/webKitDebugSession.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {OutputEvent, DebugSession, ErrorDestination} from 'vscode-debugadapter';
22
import {DebugProtocol} from 'vscode-debugprotocol';
33

44
import {WebKitDebugAdapter} from './webKitDebugAdapter';
5-
import {Handlers} from '../common/logger';
5+
import {LoggerHandler, Handlers, Tags} from '../common/logger';
66
import {Services} from '../services/debugAdapterServices';
77

88
import {AdapterProxy} from './adapter/adapterProxy';
@@ -76,7 +76,7 @@ export class WebKitDebugSession extends DebugSession {
7676

7777

7878
if (eStr === 'Error: unknowncommand') {
79-
this.sendErrorResponse(response, 1014, '[NativeScript-Debug-Adapter] Unrecognized request: ' + request.command, null, ErrorDestination.Telemetry);
79+
this.sendErrorResponse(response, 1014, '[NSDebugAdapter] Unrecognized request: ' + request.command, null, ErrorDestination.Telemetry);
8080
return;
8181
}
8282

@@ -87,8 +87,8 @@ export class WebKitDebugSession extends DebugSession {
8787
} else {
8888
// These errors show up in the message bar at the top (or nowhere), sometimes not obvious that they
8989
// come from the adapter
90-
response.message = '[NativeScript-Debug-Adapter] ' + eStr;
91-
Services.logger().log('Error: ' + e ? e.stack : eStr);
90+
response.message = '[NSDebugAdapter] ' + eStr;
91+
Services.logger().error('Error: ' + eStr, Tags.FrontendMessage);
9292
}
9393

9494
response.success = false;

0 commit comments

Comments
 (0)