From 04ca8b976382d969a8cc7e87f180accb9eb2bb8f Mon Sep 17 00:00:00 2001 From: shenlan Date: Wed, 15 Oct 2025 14:54:46 +0800 Subject: [PATCH] Fix streaming abort timeout handling (#527) --- ui/homepage/components/AskAIDialog.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ui/homepage/components/AskAIDialog.tsx b/ui/homepage/components/AskAIDialog.tsx index 2d0a3f1..4e30268 100644 --- a/ui/homepage/components/AskAIDialog.tsx +++ b/ui/homepage/components/AskAIDialog.tsx @@ -57,7 +57,12 @@ export function AskAIDialog({ ) { abortRef.current?.abort() const controller = new AbortController() - const timer = setTimeout(() => controller.abort(), timeout) + let timer: NodeJS.Timeout | null = null + const scheduleAbort = () => { + if (timer) clearTimeout(timer) + timer = setTimeout(() => controller.abort(), timeout) + } + scheduleAbort() abortRef.current = controller try { @@ -92,6 +97,7 @@ export function AskAIDialog({ const { value, done } = await reader.read() if (done) break + scheduleAbort() buffer += decoder.decode(value, { stream: true }) const parts = buffer.split('\n\n') buffer = parts.pop() || '' @@ -121,7 +127,7 @@ export function AskAIDialog({ update(answer, retrieved) return { answer, retrieved } } finally { - clearTimeout(timer) + if (timer) clearTimeout(timer) if (abortRef.current === controller) abortRef.current = null } }