fix and update
This commit is contained in:
@@ -505,6 +505,8 @@ export async function refreshAuthSession(): Promise<RefreshSessionResponse> {
|
||||
throw new ApiError('Refresh token недоступен на сервере', 401, 'NO_REFRESH');
|
||||
}
|
||||
|
||||
await ensureApiGatewayReady();
|
||||
|
||||
const refreshToken = window.localStorage.getItem(AUTH_REFRESH_KEY);
|
||||
const sessionId = window.localStorage.getItem(AUTH_SESSION_KEY);
|
||||
if (!refreshToken) {
|
||||
@@ -632,8 +634,9 @@ export function buildSystemSettingPayload(setting: Pick<SystemSetting, 'key' | '
|
||||
|
||||
const GATEWAY_RETRY_STATUS = new Set([502, 503, 504]);
|
||||
const GATEWAY_RETRY_ATTEMPTS = 6;
|
||||
const GATEWAY_WARMUP_MAX_ATTEMPTS = 24;
|
||||
const GATEWAY_WARMUP_MAX_ATTEMPTS = 40;
|
||||
const GATEWAY_WARMUP_DELAY_MS = 300;
|
||||
const GATEWAY_READY_CONSECUTIVE_OK = 2;
|
||||
|
||||
function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
@@ -651,9 +654,9 @@ export function markApiGatewayReady() {
|
||||
gatewayReadyResolved = true;
|
||||
}
|
||||
|
||||
async function probeGatewayHealth(): Promise<boolean> {
|
||||
async function probeGatewayReady(): Promise<boolean> {
|
||||
try {
|
||||
const response = await fetch(`${getApiUrl()}/health`, {
|
||||
const response = await fetch(`${getApiUrl()}/health/ready`, {
|
||||
method: 'GET',
|
||||
cache: 'no-store'
|
||||
});
|
||||
@@ -663,17 +666,23 @@ async function probeGatewayHealth(): Promise<boolean> {
|
||||
}
|
||||
}
|
||||
|
||||
/** Ждёт готовности api-gateway (кратковременные 502 после перезапуска nginx/upstream). */
|
||||
/** Ждёт готовности api-gateway и sso-core (readiness по gRPC, не liveness /health). */
|
||||
export async function ensureApiGatewayReady(force = false): Promise<void> {
|
||||
if (typeof window === 'undefined') return;
|
||||
if (gatewayReadyResolved && !force) return;
|
||||
if (gatewayReadyPromise && !force) return gatewayReadyPromise;
|
||||
|
||||
gatewayReadyPromise = (async () => {
|
||||
let consecutiveOk = 0;
|
||||
for (let attempt = 0; attempt < GATEWAY_WARMUP_MAX_ATTEMPTS; attempt++) {
|
||||
if (await probeGatewayHealth()) {
|
||||
gatewayReadyResolved = true;
|
||||
return;
|
||||
if (await probeGatewayReady()) {
|
||||
consecutiveOk += 1;
|
||||
if (consecutiveOk >= GATEWAY_READY_CONSECUTIVE_OK) {
|
||||
gatewayReadyResolved = true;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
consecutiveOk = 0;
|
||||
}
|
||||
await sleep(GATEWAY_WARMUP_DELAY_MS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user