Skip to content
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

add --fetch-urls-timeout flag #410

Merged
merged 1 commit into from
Jan 29, 2024
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
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
Loading