Skip to content

Commit 97246f8

Browse files
author
Dimitar Tachev
authored
Merge pull request #4405 from NativeScript/tachev/fix-debug-timeout
fix: increase the debugger port timeout in order to support bigger apps
2 parents f167357 + 49a12a2 commit 97246f8

File tree

6 files changed

+41
-22
lines changed

6 files changed

+41
-22
lines changed

lib/common/mobile/ios/ios-device-base.ts

+22-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as net from "net";
22
import { performanceLog } from "../../decorators";
3+
import { APPLICATION_RESPONSE_TIMEOUT_SECONDS } from "../../../constants";
34

45
export 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>;

lib/common/services/lock-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class LockService implements ILockService {
7474
}
7575

7676
filePath = filePath || this.defaultLockFilePath;
77-
fileOpts = fileOpts || this.defaultLockParams;
77+
fileOpts = fileOpts ? _.assign({}, this.defaultLockParams, fileOpts) : this.defaultLockParams;
7878

7979
return {
8080
filePath,

lib/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const AAB_EXTENSION_NAME = ".aab";
4646
export const HASHES_FILE_NAME = ".nshashes";
4747
export const TNS_NATIVE_SOURCE_GROUP_NAME = "TNSNativeSource";
4848
export const NATIVE_SOURCE_FOLDER = "src";
49+
export const APPLICATION_RESPONSE_TIMEOUT_SECONDS = 60;
4950

5051
export class PackageVersion {
5152
static NEXT = "next";

lib/device-sockets/ios/app-debug-socket-proxy-factory.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EventEmitter } from "events";
2-
import { CONNECTION_ERROR_EVENT_NAME } from "../../constants";
2+
import { CONNECTION_ERROR_EVENT_NAME, APPLICATION_RESPONSE_TIMEOUT_SECONDS } from "../../constants";
33
import * as net from "net";
44
import * as ws from "ws";
55
import temp = require("temp");
@@ -115,7 +115,15 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu
115115
port: localPort,
116116
host: "localhost",
117117
verifyClient: async (info: any, callback: (res: boolean, code?: number, message?: string) => void) => {
118-
await this.$lockService.lock(clientConnectionLockFile);
118+
await this.$lockService.lock(
119+
clientConnectionLockFile,
120+
{
121+
// increase the timeout with `APPLICATION_RESPONSE_TIMEOUT_SECONDS` as a workaround
122+
// till startApplication is resolved before the application is really started
123+
stale: (APPLICATION_RESPONSE_TIMEOUT_SECONDS + 30) * 1000,
124+
}
125+
);
126+
119127
let acceptHandshake = true;
120128
this.$logger.info("Frontend client connected.");
121129
let appDebugSocket;

lib/services/ios-debugger-port-service.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { DEBUGGER_PORT_FOUND_EVENT_NAME, ATTACH_REQUEST_EVENT_NAME } from "../common/constants";
22
import { cache } from "../common/decorators";
3+
import { APPLICATION_RESPONSE_TIMEOUT_SECONDS } from "../constants";
34

45
export class IOSDebuggerPortService implements IIOSDebuggerPortService {
56
public static DEBUG_PORT_LOG_REGEX = /NativeScript debugger has opened inspector socket on port (\d+?) for (.*)[.]/;
67
private mapDebuggerPortData: IDictionary<IIOSDebuggerPortStoredData> = {};
7-
private static DEFAULT_TIMEOUT_IN_SECONDS = 10;
88

99
constructor(private $logParserService: ILogParserService,
1010
private $iOSNotification: IiOSNotification,
@@ -14,7 +14,8 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
1414
public getPort(data: IIOSDebuggerPortInputData): Promise<number> {
1515
return new Promise((resolve, reject) => {
1616
const key = `${data.deviceId}${data.appId}`;
17-
let retryCount = Math.max(IOSDebuggerPortService.DEFAULT_TIMEOUT_IN_SECONDS * 1000 / 500, 10);
17+
const retryInterval = 500;
18+
let retryCount = Math.max(APPLICATION_RESPONSE_TIMEOUT_SECONDS * 1000 / retryInterval, 10);
1819

1920
const interval = setInterval(() => {
2021
let port = this.getPortByKey(key);
@@ -25,7 +26,7 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
2526
port = this.getPortByKey(key);
2627
retryCount--;
2728
}
28-
}, 500);
29+
}, retryInterval);
2930
});
3031
}
3132

@@ -65,7 +66,7 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
6566
if (!this.getPortByKey(`${data.deviceId}${data.appId}`)) {
6667
this.$logger.warn(`NativeScript debugger was not able to get inspector socket port on device ${data.deviceId} for application ${data.appId}.`);
6768
}
68-
}, IOSDebuggerPortService.DEFAULT_TIMEOUT_IN_SECONDS * 1000);
69+
}, APPLICATION_RESPONSE_TIMEOUT_SECONDS * 1000);
6970

7071
this.setData(data, { port: null, timer });
7172
});

test/services/ios-debugger-port-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ describe("iOSDebuggerPortService", () => {
156156
}
157157

158158
const promise = iOSDebuggerPortService.getPort({ deviceId: deviceId, appId: appId });
159-
clock.tick(20000);
159+
clock.tick(70000);
160160
const port = await promise;
161161
assert.deepEqual(port, testCase.emittedPort);
162162
});
@@ -170,7 +170,7 @@ describe("iOSDebuggerPortService", () => {
170170
}
171171

172172
const promise = iOSDebuggerPortService.getPort({ deviceId: deviceId, appId: appId });
173-
clock.tick(20000);
173+
clock.tick(70000);
174174
const port = await promise;
175175
assert.deepEqual(port, testCase.emittedPort);
176176
});

0 commit comments

Comments
 (0)