Skip to content

fix: increase the debugger port timeout in order to support bigger apps #4405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions lib/common/mobile/ios/ios-device-base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as net from "net";
import { performanceLog } from "../../decorators";
import { APPLICATION_RESPONSE_TIMEOUT_SECONDS } from "../../../constants";

export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
private cachedSockets: IDictionary<net.Socket> = {};
Expand All @@ -16,23 +17,31 @@ export abstract class IOSDeviceBase implements Mobile.IiOSDevice {

@performanceLog()
public async getDebugSocket(appId: string, projectName: string): Promise<net.Socket> {
return this.$lockService.executeActionWithLock(async () => {
if (this.cachedSockets[appId]) {
return this.cachedSockets[appId];
}
return this.$lockService.executeActionWithLock(
async () => {
if (this.cachedSockets[appId]) {
return this.cachedSockets[appId];
}

this.cachedSockets[appId] = await this.getDebugSocketCore(appId, projectName);
this.cachedSockets[appId] = await this.getDebugSocketCore(appId, projectName);

if (this.cachedSockets[appId]) {
this.cachedSockets[appId].on("close", async () => {
await this.destroyDebugSocket(appId);
});
if (this.cachedSockets[appId]) {
this.cachedSockets[appId].on("close", async () => {
await this.destroyDebugSocket(appId);
});

this.$processService.attachToProcessExitSignals(this, () => this.destroyDebugSocket(appId));
}
this.$processService.attachToProcessExitSignals(this, () => this.destroyDebugSocket(appId));
}

return this.cachedSockets[appId];
}, "ios-debug-socket.lock");
return this.cachedSockets[appId];
},
`ios-debug-socket-${this.deviceInfo.identifier}-${appId}.lock`,
{
// increase the timeout with `APPLICATION_RESPONSE_TIMEOUT_SECONDS` as a workaround
// till startApplication is resolved before the application is really started
stale: (APPLICATION_RESPONSE_TIMEOUT_SECONDS + 30) * 1000,
}
);
}

protected abstract async getDebugSocketCore(appId: string, projectName: string): Promise<net.Socket>;
Expand Down
2 changes: 1 addition & 1 deletion lib/common/services/lock-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class LockService implements ILockService {
}

filePath = filePath || this.defaultLockFilePath;
fileOpts = fileOpts || this.defaultLockParams;
fileOpts = fileOpts ? _.assign({}, this.defaultLockParams, fileOpts) : this.defaultLockParams;

return {
filePath,
Expand Down
1 change: 1 addition & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const AAB_EXTENSION_NAME = ".aab";
export const HASHES_FILE_NAME = ".nshashes";
export const TNS_NATIVE_SOURCE_GROUP_NAME = "TNSNativeSource";
export const NATIVE_SOURCE_FOLDER = "src";
export const APPLICATION_RESPONSE_TIMEOUT_SECONDS = 60;

export class PackageVersion {
static NEXT = "next";
Expand Down
12 changes: 10 additions & 2 deletions lib/device-sockets/ios/app-debug-socket-proxy-factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventEmitter } from "events";
import { CONNECTION_ERROR_EVENT_NAME } from "../../constants";
import { CONNECTION_ERROR_EVENT_NAME, APPLICATION_RESPONSE_TIMEOUT_SECONDS } from "../../constants";
import * as net from "net";
import * as ws from "ws";
import temp = require("temp");
Expand Down Expand Up @@ -115,7 +115,15 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu
port: localPort,
host: "localhost",
verifyClient: async (info: any, callback: (res: boolean, code?: number, message?: string) => void) => {
await this.$lockService.lock(clientConnectionLockFile);
await this.$lockService.lock(
clientConnectionLockFile,
{
// increase the timeout with `APPLICATION_RESPONSE_TIMEOUT_SECONDS` as a workaround
// till startApplication is resolved before the application is really started
stale: (APPLICATION_RESPONSE_TIMEOUT_SECONDS + 30) * 1000,
}
);

let acceptHandshake = true;
this.$logger.info("Frontend client connected.");
let appDebugSocket;
Expand Down
9 changes: 5 additions & 4 deletions lib/services/ios-debugger-port-service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { DEBUGGER_PORT_FOUND_EVENT_NAME, ATTACH_REQUEST_EVENT_NAME } from "../common/constants";
import { cache } from "../common/decorators";
import { APPLICATION_RESPONSE_TIMEOUT_SECONDS } from "../constants";

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

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

const interval = setInterval(() => {
let port = this.getPortByKey(key);
Expand All @@ -25,7 +26,7 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
port = this.getPortByKey(key);
retryCount--;
}
}, 500);
}, retryInterval);
});
}

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

this.setData(data, { port: null, timer });
});
Expand Down
4 changes: 2 additions & 2 deletions test/services/ios-debugger-port-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe("iOSDebuggerPortService", () => {
}

const promise = iOSDebuggerPortService.getPort({ deviceId: deviceId, appId: appId });
clock.tick(20000);
clock.tick(70000);
const port = await promise;
assert.deepEqual(port, testCase.emittedPort);
});
Expand All @@ -170,7 +170,7 @@ describe("iOSDebuggerPortService", () => {
}

const promise = iOSDebuggerPortService.getPort({ deviceId: deviceId, appId: appId });
clock.tick(20000);
clock.tick(70000);
const port = await promise;
assert.deepEqual(port, testCase.emittedPort);
});
Expand Down