mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-17 22:03:09 +00:00
uberf-8597: fix workspace handshake (#7199)
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
parent
13c03e3d24
commit
eac3f840aa
@ -37,6 +37,8 @@ export interface LoginInfo {
|
|||||||
email: string
|
email: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const connectionErrorCodes = ['ECONNRESET', 'ECONNREFUSED', 'ENOTFOUND']
|
||||||
|
|
||||||
export async function listAccountWorkspaces (token: string, region: string | null = null): Promise<BaseWorkspaceInfo[]> {
|
export async function listAccountWorkspaces (token: string, region: string | null = null): Promise<BaseWorkspaceInfo[]> {
|
||||||
const accountsUrl = getAccoutsUrlOrFail()
|
const accountsUrl = getAccoutsUrlOrFail()
|
||||||
const workspaces = await (
|
const workspaces = await (
|
||||||
@ -101,7 +103,7 @@ export async function getTransactorEndpoint (
|
|||||||
// Timeout happened
|
// Timeout happened
|
||||||
throw err
|
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))
|
await new Promise<void>((resolve) => setTimeout(resolve, 1000))
|
||||||
} else {
|
} else {
|
||||||
throw err
|
throw err
|
||||||
@ -137,8 +139,7 @@ export function withRetryConnUntilTimeout<P extends any[], T> (
|
|||||||
timeoutMs: number = 5000
|
timeoutMs: number = 5000
|
||||||
): (...params: P) => Promise<T> {
|
): (...params: P) => Promise<T> {
|
||||||
const timeout = Date.now() + timeoutMs
|
const timeout = Date.now() + timeoutMs
|
||||||
const shouldFail = (err: any): boolean =>
|
const shouldFail = (err: any): boolean => !connectionErrorCodes.includes(err?.cause?.code) || timeout < Date.now()
|
||||||
(err?.cause?.code !== 'ECONNRESET' && err?.cause?.code !== 'ECONNREFUSED') || timeout < Date.now()
|
|
||||||
|
|
||||||
return withRetry(f, shouldFail)
|
return withRetry(f, shouldFail)
|
||||||
}
|
}
|
||||||
@ -147,7 +148,7 @@ export function withRetryConnUntilSuccess<P extends any[], T> (
|
|||||||
f: (...params: P) => Promise<T>
|
f: (...params: P) => Promise<T>
|
||||||
): (...params: P) => Promise<T> {
|
): (...params: P) => Promise<T> {
|
||||||
const shouldFail = (err: any): boolean => {
|
const shouldFail = (err: any): boolean => {
|
||||||
const res = err?.cause?.code !== 'ECONNRESET' && err?.cause?.code !== 'ECONNREFUSED'
|
const res = !connectionErrorCodes.includes(err?.cause?.code)
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
console.error('Failing withRetryConnUntilSuccess with error cause:', err?.cause)
|
console.error('Failing withRetryConnUntilSuccess with error cause:', err?.cause)
|
||||||
|
Loading…
Reference in New Issue
Block a user