Skip to content

fix: improve message for Android socket connection error #5207

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
Jan 13, 2020
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
22 changes: 18 additions & 4 deletions lib/services/livesync/android-livesync-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
abstractPort: `localabstract:${configuration.appIdentifier}-livesync`
});

const connectionResult = await this.connectEventuallyUntilTimeout(this.createSocket.bind(this, port), connectTimeout);
const connectionResult = await this.connectEventuallyUntilTimeout(this.createSocket.bind(this, port), connectTimeout, configuration);
this.handleConnection(connectionResult);
}

Expand Down Expand Up @@ -299,19 +299,33 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
});
}

private connectEventuallyUntilTimeout(factory: () => ILiveSyncSocket, timeout: number): Promise<{ socket: ILiveSyncSocket, data: Buffer | string }> {
private connectEventuallyUntilTimeout(factory: () => ILiveSyncSocket, timeout: number, configuration: IAndroidLivesyncToolConfiguration): Promise<{ socket: ILiveSyncSocket, data: Buffer | string }> {
return new Promise((resolve, reject) => {
let lastKnownError: Error | string,
isConnected = false;

const connectionTimer = setTimeout(() => {
const connectionTimer = setTimeout(async () => {
if (!isConnected) {
isConnected = true;
if (this.pendingConnectionData && this.pendingConnectionData.socketTimer) {
clearTimeout(this.pendingConnectionData.socketTimer);
}

reject(lastKnownError || new Error(AndroidLivesyncTool.SOCKET_CONNECTION_TIMED_OUT_ERROR));
const applicationPid = await this.$androidProcessService.getAppProcessId(configuration.deviceIdentifier, configuration.appIdentifier);
if (!applicationPid) {
this.$logger.trace("In Android LiveSync tool, lastKnownError is: ", lastKnownError);
this.$logger.info(`Application ${configuration.appIdentifier} is not running on device ${configuration.deviceIdentifier}.`.yellow);
this.$logger.info(
`This issue may be caused by:
* crash at startup (try \`tns debug android --debug-brk\` to check why it crashes)
* different application identifier in your package.json and in your gradle files (check your identifier in \`package.json\` and in all *.gradle files in your App_Resources directory)
* device is locked
* manual closing of the application`.cyan);
reject(new Error(`Application ${configuration.appIdentifier} is not running`));
} else {
reject(lastKnownError || new Error(AndroidLivesyncTool.SOCKET_CONNECTION_TIMED_OUT_ERROR));
}

this.pendingConnectionData = null;
}
}, timeout);
Expand Down
3 changes: 2 additions & 1 deletion test/services/livesync/android-livesync-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ const createTestInjector = (socket: INetSocket, fileStreams: IDictionary<NodeJS.
testInjector.register("injector", testInjector);
testInjector.register("mobileHelper", MobileHelper);
testInjector.register("androidProcessService", {
forwardFreeTcpToAbstractPort: () => Promise.resolve("")
forwardFreeTcpToAbstractPort: () => Promise.resolve(""),
getAppProcessId: () => Promise.resolve("1234")
});
testInjector.register("LiveSyncSocket", () => socket);
testInjector.register("devicePlatformsConstants", DevicePlatformsConstants);
Expand Down