@@ -2,11 +2,13 @@ import * as path from "path";
22import * as net from "net" ;
33import Future = require( "fibers/future" ) ;
44import { sleep } from "../common/helpers" ;
5+ import { ChildProcess } from "child_process" ;
56
67class AndroidDebugService implements IDebugService {
78 private static DEFAULT_NODE_INSPECTOR_URL = "http://127.0.0.1:8080/debug" ;
89
910 private _device : Mobile . IAndroidDevice = null ;
11+ private _debuggerClientProcess : ChildProcess ;
1012
1113 constructor ( private $devicesService : Mobile . IDevicesService ,
1214 private $platformService : IPlatformService ,
@@ -19,6 +21,7 @@ class AndroidDebugService implements IDebugService {
1921 private $errors : IErrors ,
2022 private $opener : IOpener ,
2123 private $config : IConfiguration ,
24+ private $processService : IProcessService ,
2225 private $androidDeviceDiscovery : Mobile . IDeviceDiscovery ) { }
2326
2427 public get platform ( ) { return "android" ; }
@@ -187,6 +190,7 @@ class AndroidDebugService implements IDebugService {
187190 }
188191
189192 public debugStop ( ) : IFuture < void > {
193+ this . stopDebuggerClient ( ) ;
190194 return Future . fromResult ( ) ;
191195 }
192196
@@ -237,10 +241,18 @@ class AndroidDebugService implements IDebugService {
237241 let nodeInspectorModuleFilePath = require . resolve ( "node-inspector" ) ;
238242 let nodeInspectorModuleDir = path . dirname ( nodeInspectorModuleFilePath ) ;
239243 let nodeInspectorFullPath = path . join ( nodeInspectorModuleDir , "bin" , "inspector" ) ;
240- this . $childProcess . spawn ( process . argv [ 0 ] , [ nodeInspectorFullPath , "--debug-port" , port . toString ( ) ] , { stdio : "ignore" , detached : true } ) ;
244+ this . _debuggerClientProcess = this . $childProcess . spawn ( process . argv [ 0 ] , [ nodeInspectorFullPath , "--debug-port" , port . toString ( ) ] , { stdio : "ignore" , detached : true } ) ;
245+ this . $processService . attachToProcessExitSignals ( this , this . debugStop ) ;
241246 } ) . future < void > ( ) ( ) ;
242247 }
243248
249+ private stopDebuggerClient ( ) : void {
250+ if ( this . _debuggerClientProcess ) {
251+ this . _debuggerClientProcess . kill ( ) ;
252+ this . _debuggerClientProcess = null ;
253+ }
254+ }
255+
244256 private openDebuggerClient ( url : string ) : void {
245257 let defaultDebugUI = "chrome" ;
246258 if ( this . $hostInfo . isDarwin ) {
0 commit comments