Repository navigation
Reset the cache when the partial file is deleted mid-download - #23
Merged
Merged
Conversation
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.
Bug
When the partial cache file is deleted while its download runs (Android's cache management clearing the app cache, say), the downloader keeps writing into the deleted inode. Every ranged request for bytes the download already held then opens the missing path and fails with
PathNotFoundException, until the download ends. For a streamed track this is a silent stall that can last minutes.Fix
In
HttpCacheStream.request, if a downloader that has flushed bytes (filePosition > 0) is still running andfiles.activeCacheFile()no longer exists, the stream resets the cache (_resetCachewithInvalidCacheSizeException(sourceUrl, -1, sourceLength), so the deletion is reported oncacheStateStream) and queues the request instead of handing it to the old downloader. The download starts again and the request is served once its range is downloaded.Tests
test/e2e/partial_deleted_test.dart: holds the origin at half the body, deletes the partial file, then reads a range it had already downloaded. Fails without the fix (PathNotFoundException), passes with it; the full download then completes with the right hash.flutter test: all 148 pass.dart analyze lib test: no issues (flutter analyze's issues are the existing ones inbenchmarker/).## Unreleased.