From c05842fd912a6d3e711288bfe052823cd2e8bb67 Mon Sep 17 00:00:00 2001 From: JustMe Date: Mon, 19 Oct 2026 09:31:57 +0800 Subject: [PATCH] fix(web): time out API requests and flag line strips that failed to refresh [CI] --- web/display/src/LineStrips.tsx | 1 + web/shared/api/client.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/web/display/src/LineStrips.tsx b/web/display/src/LineStrips.tsx index 3a82a68..e0587e2 100644 --- a/web/display/src/LineStrips.tsx +++ b/web/display/src/LineStrips.tsx @@ -70,6 +70,7 @@ export function LineStrips({ lineId, range, m }: Props) { ) :
QUIC{fmtMs(m['rtt.p50'])}悬停看 p95 / p99 + {series.error ? 数据未更新 : null}
diff --git a/web/shared/api/client.ts b/web/shared/api/client.ts index 04d459d..5b73a4d 100644 --- a/web/shared/api/client.ts +++ b/web/shared/api/client.ts @@ -40,12 +40,16 @@ async function request(method: string, path: string, body?: unknown, init?: R const headers: Record = { Accept: 'application/json', ...authHeaders() } if (body !== undefined) headers['Content-Type'] = method === 'PATCH' ? 'application/merge-patch+json' : 'application/json' if (method !== 'GET' && csrfToken) headers['X-CSRF-Token'] = csrfToken + // 没有时限的 fetch 在被黑洞的线路上会一直挂着,轮询的界面就停在旧数据上;超时后抛错,下一轮轮询换一条连接重试 + const timeout = AbortSignal.timeout(method === 'GET' ? 15_000 : 30_000) + const signal = init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout const response = await fetch(resolveUrl(path), { method, headers, credentials: isRemote() ? 'omit' : 'include', body: body === undefined ? undefined : JSON.stringify(body), ...init, + signal, }) if (response.status === 204) return undefined as T const text = await response.text()