@@ -51,12 +51,18 @@ class AndroidDebugService implements IDebugService {
51
51
server . on ( "error" , ( err : Error ) => {
52
52
future . return ( false ) ;
53
53
} ) ;
54
- server . listen ( candidatePort , ( err : Error ) => {
55
- server . once ( "close" , ( ) => {
54
+ server . once ( "close" , ( ) => {
55
+ if ( ! future . isResolved ( ) ) { // "close" will be emitted right after "error"
56
56
future . return ( true ) ;
57
- } ) ;
57
+ }
58
+ } ) ;
59
+ server . on ( "listening" , ( err : Error ) => {
60
+ if ( err ) {
61
+ future . return ( false ) ;
62
+ }
58
63
server . close ( ) ;
59
64
} ) ;
65
+ server . listen ( candidatePort , "localhost" ) ;
60
66
61
67
return future ;
62
68
}
@@ -73,7 +79,7 @@ class AndroidDebugService implements IDebugService {
73
79
port = parseInt ( match [ 1 ] ) ;
74
80
} else {
75
81
let candidatePort = 40000 ;
76
- while ( ! this . isPortAvailable ( candidatePort ++ ) . wait ( ) ) {
82
+ for ( ; ! this . isPortAvailable ( candidatePort ) . wait ( ) ; ++ candidatePort ) {
77
83
if ( candidatePort > 65534 ) {
78
84
this . $errors . failWithoutHelp ( "Unable to find free local port." ) ;
79
85
}
@@ -88,7 +94,7 @@ class AndroidDebugService implements IDebugService {
88
94
}
89
95
90
96
private unixSocketForward ( local : number , remote : string ) : IFuture < void > {
91
- return this . device . adb . executeCommand ( [ "forward" , `tcp:${ local . toString ( ) } ` , `localabstract:${ remote } ` ] ) ;
97
+ return this . device . adb . executeCommand ( [ "forward" , `tcp:${ local } ` , `localabstract:${ remote } ` ] ) ;
92
98
}
93
99
94
100
private debugOnDevice ( ) : IFuture < void > {
0 commit comments