From eac3f840aa3fc8e900db1f9de1df99ac05880760 Mon Sep 17 00:00:00 2001 From: Alexey Zinoviev Date: Tue, 19 Nov 2024 17:35:45 +0400 Subject: [PATCH] uberf-8597: fix workspace handshake (#7199) Signed-off-by: Alexey Zinoviev --- server/client/src/account.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/client/src/account.ts b/server/client/src/account.ts index 8f2abc1aea..37216c475f 100644 --- a/server/client/src/account.ts +++ b/server/client/src/account.ts @@ -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 { 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((resolve) => setTimeout(resolve, 1000)) } else { throw err @@ -137,8 +139,7 @@ export function withRetryConnUntilTimeout

( timeoutMs: number = 5000 ): (...params: P) => Promise { 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

( f: (...params: P) => Promise ): (...params: P) => Promise { 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)