Problem/Motivation

Dynamic Page Cache (DPC) is unable to retrieve a previously stored response from cache, due to AmpEventSubscriber::onView() setting ?_wrapper_format=html at Kernel::VIEW time.

This is due to DPC first resolving url.query_args:_wrapper_format at Kernel::REQUEST time (when it tries to load the cached response, before Kernel::VIEW), then relying on resolving url.query_args:_wrapper_format at Kernel::RESPONSE time (when it stores the response in the cache, after Kernel::VIEW). Due to AmpEventSubscriber changing the value in-between the two times DPC resolves it, the cid used by DPC will not be the same when loading vs. storing in the cache, which will cause MISSes every time.

This has only been observed on node pages.

Steps to reproduce

- Install Drupal 8.9.x
- Enable amp (3.5)
- Disable page_cache
- Create a test node
- Load the test node detail page (1st time): X-Drupal-Dynamic-Cache: MISS
- Load the test node detail page (2nd time): X-Drupal-Dynamic-Cache: MISS (wrong!)

Proposed resolution

Just remove the if branch that set _wrapper_format=html for non-AMP pages (AmpEventSubscriber::onView).

Remaining tasks

- Make the bug reproducible with a Functional test.
- Fix the bug.
- Review the fix.

Issue fork amp-3207332

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jedihe created an issue. See original summary.

jedihe’s picture

Title: Setting _wrapper_format at onView interferes with Dynamic Page Cache retrieval » Setting _wrapper_format at Kernel::VIEW time interferes with Dynamic Page Cache retrieval
StatusFileSize
new1.43 KB
new2.12 KB

Let's start by properly detecting the bug, as well as explore the first idea for a fix.

The issue fork has the same code changes as the full patch.

jedihe’s picture

Looks like a typo in the test class name prevented the test runner from finding the new test.

jedihe’s picture

Alright! the test works to detect the bug :).

Judging from tests, the attempted fix works; let's try removing the if branch that caused the problem in the first place and ask for review.

jedihe’s picture

Assigned: jedihe » Unassigned
Status: Active » Needs review
jedihe’s picture

Issue summary: View changes
jedihe’s picture

Don't know what's preventing the testbot to run the new test in the MR. I'll just give the testbot patches, with the latest changes in the MR.

jedihe’s picture

Good! and now for the test-only patch.

jedihe’s picture

Issue summary: View changes

Status: Needs review » Needs work
jedihe’s picture

Status: Needs work » Needs review

Given #9 (1 fail, for the new test) is the test-only version of the MR @e5a05e1d (41 passes, 1 more than 3.x-dev), this is ready for review.

damienmckenna’s picture

The MR/patch looks good, but I'll leave someone else to RTBC it as I haven't tested it yet.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Did run into this as well.

This doesn't only affect dynamic page cache but also active menu links, or more specifically \Drupal\Core\EventSubscriber\ActiveLinkResponseFilter::setLinkActiveClass. That will end up with that wrapper format in $query and will then not mark links as active.

I don't understand why this exists in the first place, but can confirm that this causes problems and should not be done.

jedihe’s picture

Just attaching the patch for the MR @e5a05e1d. test-only patch is the same as #9.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: amp-dynamic-page-cache-fix-3207332-15.patch, failed testing. View results

berdir’s picture

Looks like HEAD passed against 9.2, is this causing a regression somehow?

jedihe’s picture

Had a look into this and found something odd: locally, I can get 8.x-3.x to trigger various failures in the test suite, but the testbot does not.

For now, I opened #3232376: Test failures on PHP 7.3, D9.2 and committed two trivial fixes, but couldn't yet understand what causes the errors in #15. I think there is some stabilization work pending in the test-suite, which is the actual cause for those errors.