Closed Bug 2077601 Opened 1 month ago Closed 23 days ago

Navigation activated from a speculation-rules prefetch isn't served from that prefetch's own cache entry

Categories

(Core :: DOM: Networking, defect, P3)

defect

Tracking

()

RESOLVED FIXED
162 Branch
Tracking Status
firefox162 --- fixed

People

(Reporter: smayya, Assigned: smayya)

References

(Blocks 2 open bugs)

Details

(Whiteboard: [necko-triaged])

Attachments

(1 external file, 1 obsolete file)

DocumentLoadListener::TryActivateFromPrefetch serves the activated navigation through a fresh HTTP cache lookup by the navigation's URL. The prefetch record keeps no reference to the cache entry it wrote, so nothing ties the navigation to that entry.

When the URLs differ (No-Vary-Search), the exact key misses and CacheStorageService::AddStorageEntry returns the first No-Vary-Search candidate on the same path, which can be an unrelated response. Since bug 2070841 skips validation for activated navigations, that response (often expired, no-store) is served without revalidation.

Evidence (no-vary-search/prefetch-single.https.html, MOZ_LOG=SpeculationRules:5,cache2:5):

  • All variants in one browser, no cache purges: 20 of 22 activated navigations got another test's entry (some executor pages send No-Vary-Search: params, making the per-test uuid ignorable); 9 failed.
  • Each variant in its own browser: every activated navigation got its own entry and passed.

Expected: an activated navigation is served only from its prefetch record's entry. E.g. keep the entry (nsICachingChannel::GetCacheToken()) on the record in PrefetchRecordParent::OnStopRequest, and skip validation only when the navigation's entry matches it (cacheEntryId). Choosing the record from the navigation's source document is tracked in bug 2076693. Clearing a document's cache entries on navigate-away (planned under this meta) reduces leftovers but doesn't replace this check.

To be investigated later: with default prefs the prefetched no-store entry (expiration time 0) is sometimes removed by MemoryPool::PurgeExpiredOrOverMemoryLimit before the navigation, so it misses and goes to the network. This also explains CI failures in tests that navigate to the exact prefetched URL (bug 2076682).

https://wpt.fyi/results/speculation-rules/prefetch/no-vary-search?label=master&label=experimental&aligned&q=prefetch-single.https.html

Blocks: 2076681

Another case: speculation-rules/prefetch/navigation-timing-delivery-type.https.html?prefetch=true&bypass_cache=true failed on try (test-linux2404-64/opt-web-platform-tests-2):
https://treeherder.mozilla.org/logviewer?job_id=597434682&repo=try&task=GUxerI2oQdmm3UKu_yFBUw.0&lineNumber=7135

TEST-UNEXPECTED-FAIL … assert_in_array: Prefetch https://web-platform.test:8443/speculation-rules/prefetch/resources/executor.sub.html?… should work. The navigated page had no Sec-Purpose: prefetch. On try it ran right after ?prefetch=true&bypass_cache=false and ?prefetch=false&bypass_cache=true in the same browser. Reordering the variants locally reproduces it.

Root cause: the prefetch is served from an existing HTTP cache entry instead of being fetched for the prefetch, so the record doesn't end up with its own response. This is the prefetch-side counterpart of comment 0. Tying cache entries to the prefetch record and the document that initiated it should cover both directions:

  • the prefetch shouldn't reuse an entry that wasn't fetched for it
  • the activated navigation should only be served from the record's own entry

Marked expected: [PASS, FAIL] with this bug for now.

https://wpt.fyi/results/speculation-rules/prefetch?label=master&label=experimental&aligned&q=navigation-timing-delivery-type.https.html

Severity: -- → S3
Priority: -- → P3
Whiteboard: [necko-triaged]

The prefetched response lives in the HTTP cache, but nothing referenced its
entry once the prefetch channel finished, so the cache could purge it before
the navigation used it (an expired no-store response is purged as soon as a
purge runs). Hold the entry in the prefetch record until the record is
canceled or destroyed.

Looking up the navigation URL in the HTTP cache can return a different
No-Vary-Search-equivalent entry than the one the prefetch stored. Open the
entry the prefetch record holds instead, read-only, so the navigation gets the
record's response as the spec requires. Records reached through redirects keep
the existing lookup for now.

Assignee: nobody → smayya
Status: NEW → ASSIGNED
Attachment #9661599 - Attachment description: WIP: Bug 2077601 - Keep the HTTP cache entry of a completed speculation-rules prefetch alive. r=#necko → Bug 2077601 - Keep the HTTP cache entry of a completed speculation-rules prefetch alive. r=#necko
Attachment #9661600 - Attachment description: WIP: Bug 2077601 - Serve a prefetch-activated navigation from the record's own cache entry. r=#necko → Bug 2077601 - Serve a prefetch-activated navigation from the record's own cache entry. r=#necko
Duplicate of this bug: 2084521
Attachment #9661599 - Attachment is obsolete: true
Pushed by smayya@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/843ac1437de0 https://hg.mozilla.org/integration/autoland/rev/0ae682bae842 Serve a prefetch-activated navigation from the record's own cache entry. r=necko-reviewers,valentin
Pushed by smayya@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/d55622ddc1f4 https://hg.mozilla.org/integration/autoland/rev/d5312493f9ce Serve a prefetch-activated navigation from the record's own cache entry. r=necko-reviewers,valentin
Status: ASSIGNED → RESOLVED
Closed: 23 days ago
Resolution: --- → FIXED
Target Milestone: --- → 162 Branch
QA Whiteboard: [qa-triage-done-c163/b162]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: