fix(webui): guard async polling against re-entrant overlap
三个 setInterval 轮询(列表 reconcile、systemInfo 快刷、6h 更新检查)调度的都是 async tick,但 setInterval 不感知 Promise 完成——当某次请求慢于轮询间隔时,下一次 tick 会在 上一次未完成时又发起,导致同类请求并发堆叠、越积越慢。 每个 tick 加在途 running 互斥:上一次刷新还在飞就跳过本次,完成(try/finally,含出错)后 恢复调度。保留已有的 document.hidden 门控与变可见补刷。慢 tick 只是被跳过、完成后自愈, 不会永久停摆。 (引 non-overlapping-poll 工具 + 给 webui 新增测试基建对 3 个轮询点属过度工程,故就地加 互斥。)
This commit is contained in:
1 file changed
+22
-6
@@ -140,12 +140,20 @@ export function AppLayout() {
|
||||
useEffect(() => {
|
||||
if (pollInterval <= 0) return;
|
||||
let cancelled = false;
|
||||
let running = false;
|
||||
const reconcileMs = Math.max(pollInterval * 10, 10_000);
|
||||
const tick = async () => {
|
||||
// Skip while the tab is hidden — SSE already carries live updates, and a
|
||||
// backgrounded tab has no UI to refresh. Re-tick on becoming visible.
|
||||
if (cancelled || document.hidden) return;
|
||||
await Promise.all([refreshQqList(), refreshProcesses(), refreshConnections()]);
|
||||
// `running` drops a tick while the previous refresh is still in flight,
|
||||
// so a slow backend can't stack overlapping requests.
|
||||
if (cancelled || document.hidden || running) return;
|
||||
running = true;
|
||||
try {
|
||||
await Promise.all([refreshQqList(), refreshProcesses(), refreshConnections()]);
|
||||
} finally {
|
||||
running = false;
|
||||
}
|
||||
};
|
||||
// Initial tick primes the lists before the SSE handshake completes
|
||||
// (avoids a flash of empty state in the chrome).
|
||||
@@ -168,9 +176,11 @@ export function AppLayout() {
|
||||
useEffect(() => {
|
||||
if (pollInterval <= 0) return;
|
||||
let cancelled = false;
|
||||
let running = false;
|
||||
const tick = async () => {
|
||||
if (cancelled || document.hidden) return;
|
||||
await refreshSystem();
|
||||
if (cancelled || document.hidden || running) return;
|
||||
running = true;
|
||||
try { await refreshSystem(); } finally { running = false; }
|
||||
};
|
||||
tick();
|
||||
const interval = setInterval(tick, pollInterval);
|
||||
@@ -187,8 +197,14 @@ export function AppLayout() {
|
||||
// list-polling above — GitHub's API is rate-limited, the result rarely
|
||||
// changes, and the server caches it anyway, so this is cheap.
|
||||
useEffect(() => {
|
||||
refreshUpdate();
|
||||
const id = setInterval(() => refreshUpdate(), 6 * 60 * 60 * 1000);
|
||||
let running = false;
|
||||
const tick = async () => {
|
||||
if (running) return;
|
||||
running = true;
|
||||
try { await refreshUpdate(); } finally { running = false; }
|
||||
};
|
||||
tick();
|
||||
const id = setInterval(tick, 6 * 60 * 60 * 1000);
|
||||
return () => clearInterval(id);
|
||||
}, [refreshUpdate]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user