Skip to content

Commit 0859256

Browse files
committed
Fix debugging of two apps at the same time
See #1377
1 parent acf353d commit 0859256

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/services/android-debug-service.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,18 @@ class AndroidDebugService implements IDebugService {
5151
server.on("error", (err: Error) => {
5252
future.return(false);
5353
});
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"
5656
future.return(true);
57-
});
57+
}
58+
});
59+
server.on("listening", (err: Error) => {
60+
if (err) {
61+
future.return(false);
62+
}
5863
server.close();
5964
});
65+
server.listen(candidatePort, "localhost");
6066

6167
return future;
6268
}
@@ -73,7 +79,7 @@ class AndroidDebugService implements IDebugService {
7379
port = parseInt(match[1]);
7480
} else {
7581
let candidatePort = 40000;
76-
while (!this.isPortAvailable(candidatePort++).wait()) {
82+
for (; !this.isPortAvailable(candidatePort).wait(); ++candidatePort) {
7783
if (candidatePort > 65534) {
7884
this.$errors.failWithoutHelp("Unable to find free local port.");
7985
}
@@ -88,7 +94,7 @@ class AndroidDebugService implements IDebugService {
8894
}
8995

9096
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}`]);
9298
}
9399

94100
private debugOnDevice(): IFuture<void> {

0 commit comments

Comments
 (0)