fix and update

This commit is contained in:
lendry
2026-06-30 14:12:20 +03:00
parent 2a88c87e94
commit 879875508f
7 changed files with 45 additions and 25 deletions

View File

@@ -682,7 +682,8 @@ const GATEWAY_RETRY_STATUS = new Set([502, 503, 504]);
const GATEWAY_RETRY_ATTEMPTS = 4;
const GATEWAY_PROBE_MAX_ATTEMPTS = 48;
const GATEWAY_PROBE_BASE_DELAY_MS = 450;
const GATEWAY_STABLE_PROBES = 3;
const GATEWAY_STABLE_PROBE_INTERVAL_MS = 800;
const GATEWAY_STABLE_MAX_ROUNDS = 18;
const API_MAX_CONCURRENT = 6;
const API_BURST_MAX_CONCURRENT = 2;
const API_BURST_WINDOW_MS = 5000;
@@ -742,24 +743,24 @@ export function subscribeApiNotReady(listener: () => void): () => void {
}
/** Несколько подряд успешных /health через nginx — защита от «один OK, потом 502». */
export async function waitForStableGateway(stableProbes = GATEWAY_STABLE_PROBES): Promise<void> {
export async function waitForStableGateway(stableProbes = 3): Promise<void> {
if (typeof window === 'undefined') return;
gatewayReadyResolved = false;
gatewayReadyAt = 0;
let streak = 0;
for (let attempt = 0; attempt < 24 && streak < stableProbes; attempt += 1) {
for (let attempt = 0; attempt < GATEWAY_STABLE_MAX_ROUNDS && streak < stableProbes; attempt += 1) {
if (await probeGatewayAlive()) {
streak += 1;
if (streak >= stableProbes) {
markApiGatewayReady();
return;
}
await sleep(500);
await sleep(GATEWAY_STABLE_PROBE_INTERVAL_MS);
} else {
streak = 0;
await sleep(Math.min(700 + attempt * 250, 2500));
await sleep(Math.min(900 + attempt * 300, 2800));
}
}