11import * as net from "net" ;
22import { performanceLog } from "../../decorators" ;
3+ import { APPLICATION_RESPONSE_TIMEOUT_SECONDS } from "../../../constants" ;
34
45export abstract class IOSDeviceBase implements Mobile . IiOSDevice {
56 private cachedSockets : IDictionary < net . Socket > = { } ;
@@ -16,23 +17,31 @@ export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
1617
1718 @performanceLog ( )
1819 public async getDebugSocket ( appId : string , projectName : string ) : Promise < net . Socket > {
19- return this . $lockService . executeActionWithLock ( async ( ) => {
20- if ( this . cachedSockets [ appId ] ) {
21- return this . cachedSockets [ appId ] ;
22- }
20+ return this . $lockService . executeActionWithLock (
21+ async ( ) => {
22+ if ( this . cachedSockets [ appId ] ) {
23+ return this . cachedSockets [ appId ] ;
24+ }
2325
24- this . cachedSockets [ appId ] = await this . getDebugSocketCore ( appId , projectName ) ;
26+ this . cachedSockets [ appId ] = await this . getDebugSocketCore ( appId , projectName ) ;
2527
26- if ( this . cachedSockets [ appId ] ) {
27- this . cachedSockets [ appId ] . on ( "close" , async ( ) => {
28- await this . destroyDebugSocket ( appId ) ;
29- } ) ;
28+ if ( this . cachedSockets [ appId ] ) {
29+ this . cachedSockets [ appId ] . on ( "close" , async ( ) => {
30+ await this . destroyDebugSocket ( appId ) ;
31+ } ) ;
3032
31- this . $processService . attachToProcessExitSignals ( this , ( ) => this . destroyDebugSocket ( appId ) ) ;
32- }
33+ this . $processService . attachToProcessExitSignals ( this , ( ) => this . destroyDebugSocket ( appId ) ) ;
34+ }
3335
34- return this . cachedSockets [ appId ] ;
35- } , "ios-debug-socket.lock" ) ;
36+ return this . cachedSockets [ appId ] ;
37+ } ,
38+ `ios-debug-socket-${ this . deviceInfo . identifier } -${ appId } .lock` ,
39+ {
40+ // increase the timeout with `APPLICATION_RESPONSE_TIMEOUT_SECONDS` as a workaround
41+ // till startApplication is resolved before the application is really started
42+ stale : ( APPLICATION_RESPONSE_TIMEOUT_SECONDS + 30 ) * 1000 ,
43+ }
44+ ) ;
3645 }
3746
3847 protected abstract async getDebugSocketCore ( appId : string , projectName : string ) : Promise < net . Socket > ;
0 commit comments