From 3010363a7de138317df7fc478aff7f6a66b622d6 Mon Sep 17 00:00:00 2001 From: Roy Razon Date: Sun, 28 Jan 2024 09:16:42 +0200 Subject: [PATCH] add `--fetch-urls-timeout` flag --- packages/cli-common/src/lib/common-flags/index.ts | 4 ++++ packages/cli/src/commands/proxy/connect.ts | 1 + packages/cli/src/commands/up.ts | 1 + packages/cli/src/commands/urls.ts | 1 + packages/core/src/commands/urls.ts | 3 +++ packages/core/src/compose-tunnel-agent-client.ts | 4 +++- 6 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/cli-common/src/lib/common-flags/index.ts b/packages/cli-common/src/lib/common-flags/index.ts index c917e204..b124ae06 100644 --- a/packages/cli-common/src/lib/common-flags/index.ts +++ b/packages/cli-common/src/lib/common-flags/index.ts @@ -101,4 +101,8 @@ export const urlFlags = { description: 'Output URLs to file', required: false, }), + 'fetch-urls-timeout': Flags.integer({ + summary: 'Timeout for fetching URLs request in milliseconds', + default: 2500, + }), } as const diff --git a/packages/cli/src/commands/proxy/connect.ts b/packages/cli/src/commands/proxy/connect.ts index 78be2fc0..a49476b5 100644 --- a/packages/cli/src/commands/proxy/connect.ts +++ b/packages/cli/src/commands/proxy/connect.ts @@ -131,6 +131,7 @@ export default class Connect extends ProfileCommand { retries: 10, onFailedAttempt: e => { this.logger.debug(`Failed to query tunnels: ${inspect(e)}`) }, }, + fetchTimeout: flags['fetch-urls-timeout'], }), { text: 'Getting tunnel URLs...' }) const urls = await filterUrls({ diff --git a/packages/cli/src/commands/up.ts b/packages/cli/src/commands/up.ts index e79e8036..b2562201 100644 --- a/packages/cli/src/commands/up.ts +++ b/packages/cli/src/commands/up.ts @@ -219,6 +219,7 @@ export default class Up extends MachineCreationDriverCommand { retries: 10, onFailedAttempt: e => { this.logger.debug(`Failed to query tunnels: ${inspect(e)}`) }, }, + fetchTimeout: flags['fetch-urls-timeout'], }), { text: 'Getting tunnel URLs...' }) const urls = await filterUrls({ diff --git a/packages/cli/src/commands/urls.ts b/packages/cli/src/commands/urls.ts index c295f301..06e3abc0 100644 --- a/packages/cli/src/commands/urls.ts +++ b/packages/cli/src/commands/urls.ts @@ -133,6 +133,7 @@ export default class Urls extends ProfileCommand { includeAccessCredentials: flags['include-access-credentials'] && (flags['access-credentials-type'] as 'api' | 'browser'), showPreevyService: flags['show-preevy-service-urls'], retryOpts: { retries: 2 }, + fetchTimeout: flags['fetch-urls-timeout'], }) const urls = await filterUrls({ diff --git a/packages/core/src/commands/urls.ts b/packages/core/src/commands/urls.ts index 6107229b..a7dff859 100644 --- a/packages/core/src/commands/urls.ts +++ b/packages/core/src/commands/urls.ts @@ -25,6 +25,7 @@ export const urls = async ({ retryOpts, showPreevyService, composeTunnelServiceUrl, + fetchTimeout, }: { serviceAndPort?: { service: string; port?: number } tunnelingKey: string | Buffer @@ -32,6 +33,7 @@ export const urls = async ({ retryOpts: retry.Options showPreevyService: boolean composeTunnelServiceUrl: string + fetchTimeout: number }) => { const credentials = await generateBasicAuthCredentials(jwtGenerator(tunnelingKey)) @@ -40,6 +42,7 @@ export const urls = async ({ retryOpts, credentials, includeAccessCredentials, + fetchTimeout, }) return flattenTunnels(tunnels).filter(tunnelFilter({ serviceAndPort, showPreevyService })) diff --git a/packages/core/src/compose-tunnel-agent-client.ts b/packages/core/src/compose-tunnel-agent-client.ts index 60864d54..0f295a43 100644 --- a/packages/core/src/compose-tunnel-agent-client.ts +++ b/packages/core/src/compose-tunnel-agent-client.ts @@ -164,16 +164,18 @@ export const queryTunnels = async ({ composeTunnelServiceUrl, credentials, includeAccessCredentials, + fetchTimeout, }: { composeTunnelServiceUrl: string credentials: { user: string; password: string } retryOpts?: retry.Options includeAccessCredentials: false | 'browser' | 'api' + fetchTimeout: number }) => { const { tunnels } = await retry(async () => { const r = await fetch( `${composeTunnelServiceUrl}/tunnels`, - { signal: AbortSignal.timeout(2500), headers: { Authorization: `Bearer ${credentials.password}` } } + { signal: AbortSignal.timeout(fetchTimeout), headers: { Authorization: `Bearer ${credentials.password}` } } ).catch(e => { throw new Error(`Failed to connect to docker proxy at ${composeTunnelServiceUrl}: ${e}`, { cause: e }) }) if (!r.ok) { throw new Error(`Failed to connect to docker proxy at ${composeTunnelServiceUrl}: ${r.status}: ${r.statusText}`)