Skip to content

manager: stop and clean cancelled downloads - #3643

Open
Zhanfg wants to merge 1 commit into
tiann:mainfrom
Zhanfg:fix/download-cancellation-cleanup
Open

manager: stop and clean cancelled downloads#3643
Zhanfg wants to merge 1 commit into
tiann:mainfrom
Zhanfg:fix/download-cancellation-cleanup

Conversation

@Zhanfg

@Zhanfg Zhanfg commented Aug 16, 2026

Copy link
Copy Markdown

Summary

Improve the Manager download lifecycle so cancelled or failed downloads do not
continue writing data or leave partial files in the Downloads directory.

Previously, cancelling a download cancelled the coroutine Job, but the blocking
response read loop did not explicitly observe coroutine cancellation. A task
could therefore continue processing data and potentially reach the completion
path after cancellation.

Failed or cancelled transfers could also leave partially downloaded files
behind. Subsequent downloads with the same filename would then be renamed,
accumulating stale partial files.

Changes

  • check coroutine cancellation while streaming response data
  • prevent a cancelled download from reaching markCompleted()
  • remove partially written files after cancellation
  • remove partially written files after download failures
  • reserve the destination filename atomically with createNewFile()
  • avoid races between simultaneous downloads choosing the same target name
  • handle target-directory and target-file reservation failures through the
    normal failure/cleanup lifecycle
  • cancel the active OkHttp Call together with the coroutine Job, so cancellation can interrupt a blocking network read
  • preserve the Cancelled state when OkHttp surfaces call cancellation as an IOException

Testing

  • clean assembleRelease -PIS_PR_BUILD=true passed before the final rebase
  • rebased onto current main (af62466b70c0ebf8f9340e3a9bf0a487d804ca66)
  • post-rebase diff contains one clean commit touching only DownloadManager.kt and DownloadService.kt
  • fresh upstream Build Manager CI is awaiting upstream approval

@github-actions
github-actions Bot force-pushed the fix/download-cancellation-cleanup branch 3 times, most recently from 65550e6 to 26b09c0 Compare August 16, 2026 05:01
@YuKongA
YuKongA requested a balanced review from Copilot August 17, 2026 06:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves Manager download cancellation, cleanup, and destination reservation.

Changes:

  • Cancels active OkHttp calls and observes coroutine cancellation.
  • Deletes partial files on cancellation or failure.
  • Atomically reserves unique destination files.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread manager/app/src/main/java/me/weishu/kernelsu/ui/util/DownloadService.kt Outdated
@Zhanfg
Zhanfg force-pushed the fix/download-cancellation-cleanup branch from 56a008c to 605a186 Compare August 20, 2026 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants