use abort reason to detect user-initiated cancels

This commit is contained in:
Ben Gauger 2026-04-02 15:19:59 -06:00
parent 6401021364
commit a02d43582a
2 changed files with 4 additions and 3 deletions

View File

@ -67,7 +67,7 @@ export class RunDownloadJob {
if (val) {
await cancelRedis.del(RunDownloadJob.cancelKey(job.id!))
userCancelled = true
abortController.abort()
abortController.abort('user-cancel')
}
} catch {
// Redis errors are non-fatal; in-process AbortController covers same-process cancels
@ -184,7 +184,8 @@ export class RunDownloadJob {
} catch (error: any) {
// Only prevent retries for user-initiated cancellations. BullMQ lock mismatches
// can also abort the stream, and those should be retried with backoff.
if (userCancelled) {
// Check both the flag (Redis poll) and abort reason (in-process cancel).
if (userCancelled || abortController.signal.reason === 'user-cancel') {
throw new UnrecoverableError(`Download cancelled: ${error.message}`)
}
throw error

View File

@ -125,7 +125,7 @@ export class DownloadService {
await RunDownloadJob.signalCancel(jobId)
// Also try in-memory abort (works if worker is in same process)
RunDownloadJob.abortControllers.get(jobId)?.abort()
RunDownloadJob.abortControllers.get(jobId)?.abort('user-cancel')
RunDownloadJob.abortControllers.delete(jobId)
// Poll for terminal state (up to 4s at 250ms intervals) — cooperates with BullMQ's lifecycle