1
1
import * as net from "net" ;
2
2
import { performanceLog } from "../../decorators" ;
3
+ import { APPLICATION_RESPONSE_TIMEOUT_SECONDS } from "../../../constants" ;
3
4
4
5
export abstract class IOSDeviceBase implements Mobile . IiOSDevice {
5
6
private cachedSockets : IDictionary < net . Socket > = { } ;
@@ -16,23 +17,31 @@ export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
16
17
17
18
@performanceLog ( )
18
19
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
+ }
23
25
24
- this . cachedSockets [ appId ] = await this . getDebugSocketCore ( appId , projectName ) ;
26
+ this . cachedSockets [ appId ] = await this . getDebugSocketCore ( appId , projectName ) ;
25
27
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
+ } ) ;
30
32
31
- this . $processService . attachToProcessExitSignals ( this , ( ) => this . destroyDebugSocket ( appId ) ) ;
32
- }
33
+ this . $processService . attachToProcessExitSignals ( this , ( ) => this . destroyDebugSocket ( appId ) ) ;
34
+ }
33
35
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
+ ) ;
36
45
}
37
46
38
47
protected abstract async getDebugSocketCore ( appId : string , projectName : string ) : Promise < net . Socket > ;
0 commit comments