fix: order concurrent instance probes and honour the probe budget

Startup warm-up, opening the switcher and the refresh button can all probe at
once, and a relay host working through tunnel retries takes an order of
magnitude longer than a loopback one — so a slow older run landed last and
replaced a fresh "ok" with its own stale "unreachable". Each host now records
which run owns its status; a status from the switch flow outranks any probe
still running for it.

Each relay attempt is also capped by what is left of the 15s budget rather than
the full per-request timeout, so an attempt started just under the deadline can
no longer run the whole 8s past it.
This commit is contained in:
Bohdan Triapitsyn
2026-09-03 11:49:35 +03:00
parent f0ced9d361
commit 0107abb32d
3 changed files with 65 additions and 4 deletions
+8 -2
View File
@@ -415,10 +415,11 @@ const RELAY_PROBE_RETRY_DELAY_MS = 400;
const fetchRelayProbe = async (
tunnel: ReturnType<typeof createRelayTunnelClient>,
path: string,
timeoutMs: number,
init?: RequestInit,
): Promise<Response> => {
const controller = new AbortController();
const timer = window.setTimeout(() => controller.abort(), RELAY_PROBE_TIMEOUT_MS);
const timer = window.setTimeout(() => controller.abort(), timeoutMs);
try {
return await tunnel.fetch(path, { ...init, signal: controller.signal });
} finally {
@@ -448,8 +449,13 @@ const fetchRelayProbeUntilDeadline = async (
init?: RequestInit,
): Promise<Response> => {
for (;;) {
// Every attempt is capped by what is LEFT of the budget, not by the full
// per-request timeout: an attempt started just under the deadline would
// otherwise run the whole 8s past it, and the switch flow waits on this.
const remainingMs = deadline - Date.now();
if (remainingMs <= 0) throw new Error('relay probe deadline exceeded');
try {
return await fetchRelayProbe(tunnel, path, init);
return await fetchRelayProbe(tunnel, path, Math.min(RELAY_PROBE_TIMEOUT_MS, remainingMs), init);
} catch (error) {
if (tunnel.getStatus().state === 'error') throw error;
if (Date.now() >= deadline) throw error;