fix(desktop): wrap pull and STT download aborts into D3ROError on dispose

Catch pre-header fetch and stream rejections in LocalLLMService._doPullModel and map disposed or aborted pulls to ErrorCode.LLMProcessingCancelled (and unexpected failures to ErrorCode.LLMServerUnreachable). Convert disposed fetch aborts and JSON body aborts in LocalSTTService._fetchDownload and downloadModel into ErrorCode.STTModelDownloadCancelled while wrapping network or timeout errors as ErrorCode.STTModelDownloadFailed.
This commit is contained in:
Yun Chan 2026-11-14 15:13:46 +09:00
parent fc5d45312c
commit 3f9e412257
4 changed files with 103 additions and 3 deletions

View file

@ -882,6 +882,15 @@ class LocalLLMService extends EventEmitter {
}
logger.info(`Pull 완료: ${modelId}`)
} catch (err) {
if (this._disposed || controller.signal.aborted) {
throw new D3ROError(ErrorCode.LLMProcessingCancelled, `Pull cancelled: ${modelId}`)
}
if (err instanceof D3ROError) throw err
throw new D3ROError(
ErrorCode.LLMServerUnreachable,
`Pull 실패: ${err instanceof Error ? err.message : String(err)}`
)
} finally {
controller.signal.removeEventListener('abort', onAbort)
this._pullControllers.delete(controller)

View file

@ -551,6 +551,9 @@ class LocalSTTService extends EventEmitter {
if (startRes.ok) {
const started = (await startRes.json()) as { status: string }
if (this._disposed) {
throw new D3ROError(ErrorCode.STTModelDownloadCancelled, `모델 다운로드 취소: ${modelId}`)
}
if (started.status === 'done') {
this._emitDownloadProgress(modelId, 100, 0, 0, 0)
return
@ -1047,10 +1050,27 @@ class LocalSTTService extends EventEmitter {
}
const controller = new AbortController()
this._downloadControllers.add(controller)
const timer = setTimeout(() => controller.abort(), timeoutMs)
let timedOut = false
const timer = setTimeout(() => {
timedOut = true
controller.abort()
}, timeoutMs)
timer.unref?.()
try {
return await fetch(url, { ...init, signal: controller.signal })
const response = await fetch(url, { ...init, signal: controller.signal })
if (this._disposed) {
throw new D3ROError(ErrorCode.STTModelDownloadCancelled, 'LocalSTTService가 dispose되었습니다')
}
return response
} catch (err) {
if (this._disposed || (!timedOut && controller.signal.aborted)) {
throw new D3ROError(ErrorCode.STTModelDownloadCancelled, 'LocalSTTService가 dispose되었습니다')
}
if (err instanceof D3ROError) throw err
throw new D3ROError(
ErrorCode.STTModelDownloadFailed,
`다운로드 요청 실패: ${err instanceof Error ? err.message : String(err)}`,
)
} finally {
clearTimeout(timer)
this._downloadControllers.delete(controller)