@@ -32,7 +32,8 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
32
32
private $iOSNotification : IiOSNotification ,
33
33
private $iOSSocketRequestExecutor : IiOSSocketRequestExecutor ,
34
34
private $processService : IProcessService ,
35
- private $socketProxyFactory : ISocketProxyFactory ) {
35
+ private $socketProxyFactory : ISocketProxyFactory ,
36
+ private $net : INet ) {
36
37
super ( device , $devicesService ) ;
37
38
this . $processService . attachToProcessExitSignals ( this , this . debugStop ) ;
38
39
this . $socketProxyFactory . on ( CONNECTION_ERROR_EVENT_NAME , ( e : Error ) => this . emit ( CONNECTION_ERROR_EVENT_NAME , e ) ) ;
@@ -125,29 +126,28 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
125
126
const lineStream = byline ( child_process . stdout ) ;
126
127
this . _childProcess = child_process ;
127
128
128
- await new Promise ( ( resolve : ( ) => void , reject ) => {
129
- lineStream . on ( 'data' , ( line : NodeBuffer ) => {
130
- const lineText = line . toString ( ) ;
131
- if ( lineText && _ . startsWith ( lineText , debugData . applicationIdentifier ) ) {
132
- const pid = getPidFromiOSSimulatorLogs ( debugData . applicationIdentifier , lineText ) ;
133
- if ( ! pid ) {
134
- this . $logger . trace ( `Line ${ lineText } does not contain PID of the application ${ debugData . applicationIdentifier } .` ) ;
135
- return ;
136
- }
137
-
138
- this . _lldbProcess = this . $childProcess . spawn ( "lldb" , [ "-p" , pid ] ) ;
139
- if ( log4js . levels . TRACE . isGreaterThanOrEqualTo ( this . $logger . getLevel ( ) ) ) {
140
- this . _lldbProcess . stdout . pipe ( process . stdout ) ;
141
- }
142
- this . _lldbProcess . stderr . pipe ( process . stderr ) ;
143
- this . _lldbProcess . stdin . write ( "process continue\n" ) ;
144
- this . connectToApplicationOnEmulator ( debugData . deviceIdentifier ) . then ( resolve , reject ) ;
145
- } else {
146
- process . stdout . write ( line + "\n" ) ;
129
+ lineStream . on ( 'data' , ( line : NodeBuffer ) => {
130
+ const lineText = line . toString ( ) ;
131
+ if ( lineText && _ . startsWith ( lineText , debugData . applicationIdentifier ) ) {
132
+ const pid = getPidFromiOSSimulatorLogs ( debugData . applicationIdentifier , lineText ) ;
133
+ if ( ! pid ) {
134
+ this . $logger . trace ( `Line ${ lineText } does not contain PID of the application ${ debugData . applicationIdentifier } .` ) ;
135
+ return ;
147
136
}
148
- } ) ;
137
+
138
+ this . _lldbProcess = this . $childProcess . spawn ( "lldb" , [ "-p" , pid ] ) ;
139
+ if ( log4js . levels . TRACE . isGreaterThanOrEqualTo ( this . $logger . getLevel ( ) ) ) {
140
+ this . _lldbProcess . stdout . pipe ( process . stdout ) ;
141
+ }
142
+ this . _lldbProcess . stderr . pipe ( process . stderr ) ;
143
+ this . _lldbProcess . stdin . write ( "process continue\n" ) ;
144
+ } else {
145
+ process . stdout . write ( line + "\n" ) ;
146
+ }
149
147
} ) ;
150
148
149
+ await this . waitForBackendPortToBeOpened ( debugData . deviceIdentifier ) ;
150
+
151
151
return this . wireDebuggerClient ( debugData , debugOptions ) ;
152
152
}
153
153
@@ -158,13 +158,13 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
158
158
159
159
const iOSEmulatorService = < Mobile . IiOSSimulatorService > this . $iOSEmulatorServices ;
160
160
await iOSEmulatorService . postDarwinNotification ( attachRequestMessage ) ;
161
- await this . connectToApplicationOnEmulator ( debugData . deviceIdentifier ) ;
161
+ await this . waitForBackendPortToBeOpened ( debugData . deviceIdentifier ) ;
162
162
return result ;
163
163
}
164
164
165
- private async connectToApplicationOnEmulator ( deviceIdentifier : string ) : Promise < void > {
166
- const socket = await this . $iOSEmulatorServices . connectToPort ( { port : inspectorBackendPort } ) ;
167
- if ( ! socket ) {
165
+ private async waitForBackendPortToBeOpened ( deviceIdentifier : string ) : Promise < void > {
166
+ const portListens = await this . $net . waitForPortToListen ( { port : inspectorBackendPort , timeout : 10000 , interval : 200 } ) ;
167
+ if ( ! portListens ) {
168
168
const error = < Mobile . IDeviceError > new Error ( "Unable to connect to application. Ensure application is running on simulator." ) ;
169
169
error . deviceIdentifier = deviceIdentifier ;
170
170
throw error ;
0 commit comments