fix(cdn): serialize refresh and snapshot persisted cache metadata#2264
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(cdn): serialize refresh and snapshot persisted cache metadata#2264cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
Concurrent _refreshIfStale() calls (cold start + lifecycle background) could persist a manifest body with a mismatched etag/lastUpdatedAt because _saveCachedState read instance fields at async write time. On next launch If-None-Match could skip re-download while the cached body was wrong. Serialize overlapping refreshes and pass etag/timestamp snapshots into _saveCachedState so SharedPreferences always stores a consistent tuple. Co-authored-by: Sharjeel Yunus <sharjeelyunus@users.noreply.github.com>
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 and impact
Trigger: A CDN-backed app loads from cache and kicks off
_refreshIfStale()on cold start; the user backgrounds the app before that refresh finishes, triggering a second_refreshIfStale()from lifecyclepaused/inactive.Impact: Overlapping refreshes mutated shared
_etag,_lastUpdatedAt, and_artifactCache, while_saveCachedState()read_etagand_lastUpdatedAtat async write time—not paired with themanifestJsonargument. A slower save could persist manifest A with etag B. On the next cold start,If-None-Matchcould return 304 and skip re-download while the cached manifest body was wrong, leaving the app on stale or mismatched screens/scripts for the session.Root cause
_refreshIfStale()calls._saveCachedState()used fire-and-forget async closure that sampled instance fields at write time instead of snapshotting metadata with the manifest body being saved.Fix
_refreshIfStale()calls via_refreshSerialso only one refresh mutates in-memory state at a time.etagandlastUpdatedAtsnapshots into_saveCachedState(); extractcdnPersistedCacheEntry()for testability.Validation
modules/ensemble/test/cdn_provider_test.dartforcdnPersistedCacheEntryand snapshot-based_saveCachedState.modules/ensemble:flutter test test/cdn_provider_test.dartDuplicate check
cursor/critical-bug-remediation-76ab) — premature_lastUpdatedAtcommit on failed manifest fetch; different root cause (failed download, not concurrent save pairing).