From ac33e15be782fc0ceaf31975eab8a88a4b5c198e Mon Sep 17 00:00:00 2001 From: Roy Razon Date: Wed, 26 Jul 2023 19:16:40 +0300 Subject: [PATCH] fix: tunnels query retry in up --- packages/cli/src/commands/up.ts | 7 +++++++ packages/cli/src/commands/urls.ts | 1 + packages/core/src/commands/urls.ts | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/up.ts b/packages/cli/src/commands/up.ts index 0e0e33f0..77c8f70a 100644 --- a/packages/cli/src/commands/up.ts +++ b/packages/cli/src/commands/up.ts @@ -4,6 +4,7 @@ import { telemetryEmitter, } from '@preevy/core' import { tunnelServerFlags } from '@preevy/cli-common' +import { inspect } from 'util' import { tunnelServerHello } from '../tunnel-server-client' import MachineCreationDriverCommand from '../machine-creation-driver-command' import { envIdFlags, urlFlags } from '../common-flags' @@ -90,6 +91,12 @@ export default class Up extends MachineCreationDriverCommand { envId, tunnelingKey, includeAccessCredentials: flags['include-access-credentials'], + retryOpts: { + minTimeout: 1000, + maxTimeout: 2000, + retries: 10, + onFailedAttempt: e => { this.logger.debug(`Failed to query tunnels: ${inspect(e)}`) }, + }, }) const urls = await filterUrls({ diff --git a/packages/cli/src/commands/urls.ts b/packages/cli/src/commands/urls.ts index 737a2953..64ff0f86 100644 --- a/packages/cli/src/commands/urls.ts +++ b/packages/cli/src/commands/urls.ts @@ -88,6 +88,7 @@ export default class Urls extends ProfileCommand { serviceAndPort: args.service ? { service: args.service, port: args.port } : undefined, tunnelingKey, includeAccessCredentials: flags['include-access-credentials'], + retryOpts: { retries: 2 }, }) const urls = await filterUrls({ diff --git a/packages/core/src/commands/urls.ts b/packages/core/src/commands/urls.ts index e8a28394..a7dd78b0 100644 --- a/packages/core/src/commands/urls.ts +++ b/packages/core/src/commands/urls.ts @@ -1,14 +1,24 @@ +import retry from 'p-retry' import { generateBasicAuthCredentials, jwtGenerator } from '../credentials' import { queryTunnels } from '../compose-tunnel-agent-client' import { flattenTunnels, tunnelUrlsForEnv } from '../tunneling' -export const urls = async ({ envId, rootUrl, clientId, serviceAndPort, tunnelingKey, includeAccessCredentials }: { +export const urls = async ({ + envId, + rootUrl, + clientId, + serviceAndPort, + tunnelingKey, + includeAccessCredentials, + retryOpts, +}: { envId: string rootUrl: string clientId: string serviceAndPort?: { service: string; port?: number } tunnelingKey: string | Buffer includeAccessCredentials: boolean + retryOpts: retry.Options }) => { const tunnelUrlsForService = tunnelUrlsForEnv({ envId, rootUrl: new URL(rootUrl), clientId }) @@ -16,7 +26,7 @@ export const urls = async ({ envId, rootUrl, clientId, serviceAndPort, tunneling const { tunnels } = await queryTunnels({ tunnelUrlsForService, - retryOpts: { retries: 2 }, + retryOpts, credentials, includeAccessCredentials, })