manager: stop and clean cancelled downloads - #3643
Open
Zhanfg wants to merge 1 commit into
Open
Conversation
github-actions
Bot
force-pushed
the
fix/download-cancellation-cleanup
branch
3 times, most recently
from
August 16, 2026 05:01
65550e6 to
26b09c0
Compare
Contributor
There was a problem hiding this comment.
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.
Zhanfg
force-pushed
the
fix/download-cancellation-cleanup
branch
from
August 20, 2026 01:03
56a008c to
605a186
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
normal failure/cleanup lifecycle
Calltogether with the coroutineJob, so cancellation can interrupt a blocking network readCancelledstate when OkHttp surfaces call cancellation as anIOExceptionTesting
clean assembleRelease -PIS_PR_BUILD=truepassed before the final rebasemain(af62466b70c0ebf8f9340e3a9bf0a487d804ca66)DownloadManager.ktandDownloadService.kt