Skip to content

Commit

Permalink
add --fetch-urls-timeout flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Razon committed Jan 28, 2024
1 parent d019836 commit 3010363
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/cli-common/src/lib/common-flags/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions packages/cli/src/commands/proxy/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export default class Connect extends ProfileCommand<typeof Connect> {
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({
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export default class Up extends MachineCreationDriverCommand<typeof Up> {
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({
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export default class Urls extends ProfileCommand<typeof Urls> {
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({
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/commands/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ export const urls = async ({
retryOpts,
showPreevyService,
composeTunnelServiceUrl,
fetchTimeout,
}: {
serviceAndPort?: { service: string; port?: number }
tunnelingKey: string | Buffer
includeAccessCredentials: false | 'browser' | 'api'
retryOpts: retry.Options
showPreevyService: boolean
composeTunnelServiceUrl: string
fetchTimeout: number
}) => {
const credentials = await generateBasicAuthCredentials(jwtGenerator(tunnelingKey))

Expand All @@ -40,6 +42,7 @@ export const urls = async ({
retryOpts,
credentials,
includeAccessCredentials,
fetchTimeout,
})

return flattenTunnels(tunnels).filter(tunnelFilter({ serviceAndPort, showPreevyService }))
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/compose-tunnel-agent-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down

0 comments on commit 3010363

Please sign in to comment.