Replace windows dns workaround with single lookup

Change-type: patch
Connects-to: #1518
Resolves: #1727
Signed-off-by: Scott Lowe <scott@balena.io>
This commit is contained in:
Scott Lowe 2020-05-22 12:27:19 +02:00 committed by Balena CI
parent e5861a708e
commit 1c354c800b
2 changed files with 12 additions and 27 deletions

View File

@ -34,7 +34,6 @@ import {
loadProject,
makeBuildTasks,
} from '../compose_ts';
import { workaroundWindowsDnsIssue } from '../helpers';
import Logger = require('../logger');
import { DeviceAPI, DeviceInfo } from './api';
import * as LocalPushErrors from './errors';
@ -125,6 +124,18 @@ export async function deployToDevice(opts: DeviceDeployOptions): Promise<void> {
const { exitWithExpectedError } = await import('../../errors');
const { displayDeviceLogs } = await import('./logs');
// Resolve .local addresses to IP to avoid
// issue with Windows and rapid repeat lookups.
// see: https://github.com/balena-io/balena-cli/issues/1518
if (opts.deviceHost.includes('.local')) {
const util = await import('util');
const dns = await import('dns');
const { address } = await util.promisify(dns.lookup)(opts.deviceHost, {
family: 4,
});
opts.deviceHost = address;
}
const api = new DeviceAPI(globalLogger, opts.deviceHost);
// First check that we can access the device with a ping
@ -137,8 +148,6 @@ export async function deployToDevice(opts: DeviceDeployOptions): Promise<void> {
);
}
await workaroundWindowsDnsIssue(opts.deviceHost);
const versionError = new Error(
'The supervisor version on this remote device does not support multicontainer local mode. ' +
'Please update your device to balenaOS v2.20.0 or greater from the dashboard.',
@ -166,8 +175,6 @@ export async function deployToDevice(opts: DeviceDeployOptions): Promise<void> {
}
}
await workaroundWindowsDnsIssue(opts.deviceHost);
globalLogger.logInfo(`Starting build on device ${opts.deviceHost}`);
const project = await loadProject(globalLogger, {
@ -193,8 +200,6 @@ export async function deployToDevice(opts: DeviceDeployOptions): Promise<void> {
// Try to detect the device information
const deviceInfo = await api.getDeviceInformation();
await workaroundWindowsDnsIssue(opts.deviceHost);
let buildLogs: Dictionary<string> | undefined;
if (!opts.nolive) {
buildLogs = {};
@ -230,8 +235,6 @@ export async function deployToDevice(opts: DeviceDeployOptions): Promise<void> {
await api.setTargetState(targetState);
await workaroundWindowsDnsIssue(opts.deviceHost);
// Now that we've set the target state, the device will do it's thing
// so we can either just display the logs, or start a livepush session
// (whilst also display logs)

View File

@ -326,24 +326,6 @@ function windowsCmdExeEscapeArg(arg: string): string {
return `"${arg.replace(/["]/g, '""')}"`;
}
/**
* Workaround a window system bug which causes multiple rapid DNS lookups
* to fail for mDNS.
*
* It introduces a simple pause, and should be used between operations that
* trigger mDNS resolutions.
*
* Windows bug: https://support.microsoft.com/en-gb/help/4057932/getaddrinfo-failed-with-wsahost-not-found-11001-error
*/
export async function workaroundWindowsDnsIssue(ipOrHostname: string) {
// 300ms seemed to be the smallest delay that worked reliably but may
// vary between systems.
const delay = 500;
if (process.platform === 'win32' && ipOrHostname.includes('.local')) {
await new Promise(r => setTimeout(r, delay));
}
}
/**
* Error handling wrapper around the npm `which` package:
* "Like the unix which utility. Finds the first instance of a specified