uberf-8597: fix workspace handshake (#7199)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2024-11-19 17:35:45 +04:00 committed by GitHub
parent 13c03e3d24
commit eac3f840aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -37,6 +37,8 @@ export interface LoginInfo {
email: string
}
const connectionErrorCodes = ['ECONNRESET', 'ECONNREFUSED', 'ENOTFOUND']
export async function listAccountWorkspaces (token: string, region: string | null = null): Promise<BaseWorkspaceInfo[]> {
const accountsUrl = getAccoutsUrlOrFail()
const workspaces = await (
@ -101,7 +103,7 @@ export async function getTransactorEndpoint (
// Timeout happened
throw err
}
if (err?.cause?.code === 'ECONNRESET' || err?.cause?.code === 'ECONNREFUSED') {
if (connectionErrorCodes.includes(err?.cause?.code)) {
await new Promise<void>((resolve) => setTimeout(resolve, 1000))
} else {
throw err
@ -137,8 +139,7 @@ export function withRetryConnUntilTimeout<P extends any[], T> (
timeoutMs: number = 5000
): (...params: P) => Promise<T> {
const timeout = Date.now() + timeoutMs
const shouldFail = (err: any): boolean =>
(err?.cause?.code !== 'ECONNRESET' && err?.cause?.code !== 'ECONNREFUSED') || timeout < Date.now()
const shouldFail = (err: any): boolean => !connectionErrorCodes.includes(err?.cause?.code) || timeout < Date.now()
return withRetry(f, shouldFail)
}
@ -147,7 +148,7 @@ export function withRetryConnUntilSuccess<P extends any[], T> (
f: (...params: P) => Promise<T>
): (...params: P) => Promise<T> {
const shouldFail = (err: any): boolean => {
const res = err?.cause?.code !== 'ECONNRESET' && err?.cause?.code !== 'ECONNREFUSED'
const res = !connectionErrorCodes.includes(err?.cause?.code)
if (res) {
console.error('Failing withRetryConnUntilSuccess with error cause:', err?.cause)