magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

FPC Cache via Files or Redis does not work on Magento 2.4.7 for multi-view stores #39221

Open dandrikop opened 1 month ago

dandrikop commented 1 month ago

Preconditions and environment

This bug report is actually related with the issue: https://github.com/magento/magento2/issues/38626

Besides the Files used as the default medium for FPC, I tested Redis with Magento 2.4.7-p2 and FPC did not work. Namely it seems that cached content is stored at Files or Redis. The problem is that Magento cannot somehow identify the cached pages so it thinks that they have not been cached.

This problem is No-Go for Magento 2.4.7 for store owners with multi-domain and multi-view Magento installations, as Magento without FPC is out-of-question. It is said that the problem will be fixed at Magento 2.4.8. However, a patch should become available at Magento Quality Patches; otherwise store owners with multi-domain and multi-view Magento installations should stay at version 2.4.6 till 2.4.8 is released.

Steps to reproduce

  1. Set the multi-view store to Developer mode.
  2. Visit various pages on the front-end.
  3. Monitor the value of the HTTP header "X-Magento-Cache-Debug".

Expected result

The value of the HTTP header "X-Magento-Cache-Debug" is HIT for subsequent requests of the same page.

Actual result

The value of the HTTP header "X-Magento-Cache-Debug" is always MISS no matter how many times a page has been visited at the front-end.

Additional information

No response

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 month ago

Hi @dandrikop. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.

dandrikop commented 1 month ago

It is absolutely necessary to have patch available at Magento quality patches for this issue:

https://experienceleague.adobe.com/tools/commerce-quality-patches/index.html

This is a serious problem, as FPC is a crucial performance factor for Magento.

m2-assistant[bot] commented 1 month ago

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Hotel commented 1 month ago

Hello @dandrikop,

Thanks for the report and collaboration!

We are discussing this issue internally, meanwhile please use the below commits to fix this issue:

https://github.com/search?q=repo%3Amagento%2Fmagento2+AC-11819&type=commits

We are moving this issue On Hold.

Thanks

engcom-Hotel commented 1 month ago

Hello @dandrikop,

We have tried to reproduce the issue in 2.4.7-p3 with both default FPC and Redis. and for us the issue is not reproducible. We have created multiple store views to reproduce the issue.

The first time when we access a store view it shows as Miss and the next time it shows as Hit. Please refer to the below screenshot for reference:

English Storeview image image

French Storeview image image

Please let us know if we have missed anything.

Thanks

dandrikop commented 1 month ago

The error depends on the implementation. My multi-store implementation has 7 websites, each website has one store, and each store has one store view. The routing at the appropriate store view is regulated by the .htaccess file with directives such as the following ones:

SetEnvIf Host fr.dlastore.com MAGE_RUN_CODE=french_dla SetEnvIf Host fr.dlastore.com MAGE_RUN_TYPE=store

This problem has been reproduced and identified with AC-11819. My concern is that we'd better have a patch available at:

https://experienceleague.adobe.com/tools/commerce-quality-patches/index.html

engcom-Hotel commented 1 month ago

Hello @dandrikop,

Thanks for the input.

We have tried to reproduce the issue with the multi-websites and multi-stores, and the issue has been reproducible for us. Let me keep this issue on hold to discuss it with the PO.

We will keep you posted.

Thanks

engcom-Hotel commented 3 weeks ago

Hello @dandrikop,

Could you please confirm if you are running the above-mentioned scenario (multi-store, multi-website) with Varnish configured? If so, what is the value of the x-magento-cache-debug header?

dandrikop commented 3 weeks ago

Hello @engcom-Hotel ,

I'm running the above scenario with Files for Magento FPC. My app/etc/env.php file contains the below code for the section 'cache':

'cache' => [ 'graphql' => [ 'id_salt' => 'i38cdiM3Hdrq2PKAPJ5NQNyUbZkSqCUe' ], 'frontend' => [ 'default' => [ 'id_prefix' => '8e8_' ], 'page_cache' => [ 'id_prefix' => '8e8_' ] ], 'allow_parallel_generation' => false ]

The HTTP header x-magento-cache-debug was always MISS, though I could find the relevant files under the directory var/page_cache/mage--*. This gave me the impression, that the content was indeed cached, but somehow it was not fetched from the Magento FPC when it was requested again. To be more precise, the behavior was as follows:

  1. I visited a page of my store and noticed that the HTTP header x-magento-cache-debug=MISS.
  2. I found the generated file var/page_cache/mage--0/mage---8e8_6B4147C5910C9E127263E348A729BC033906CBBF and noted its timestamp.
  3. I revisited the page and noticed again that the HTTP header x-magento-cache-debug=MISS.
  4. I rechecked the file var/page_cache/mage--0/mage---8e8_6B4147C5910C9E127263E348A729BC033906CBBF and its timestamp was updated.

I also tried the same scenario with Redis Magento FPC, and the result was the same as with Files. I have not tested the scenario with Varnish. This issue is supposed to be resolved at Magento 2.4.8, but this is a serious bug that needs to be resolved as soon as possible, given that under these circumstances we cannot upgrade to Magento 2.4.7. I recommend that you issue a patch published at:

https://experienceleague.adobe.com/tools/commerce-quality-patches/index.html

engcom-Hotel commented 1 week ago

Keeping this issue On hold till further updates.

MartinL1983 commented 1 week ago

Hello!

We encountered this issue yesterday on our staging environment and did some investigation. We discovered a difference between the results returned by $this->identifier->getValue() and $this->identifierForSave->getValue() in PageCache/Kernel.php.

Here are the values being returned:

It’s clear that one of the methods is returning an unexpected value. We’re not yet certain which one. Logically, it seems the hashed version is the correct value, but we are also unsure if MAGE_RUN_TYPE and MAGE_RUN_CODE are meant to be part of the hash.

Since it’s surprising that an issue this small hasn’t been identified by others, we are continuing to investigate to confirm if this is indeed the root cause.

For now, we’re using the provided patch and haven’t observed any negative effects while doing so. kernel.patch.txt

We’ll post any new information we find here.

Does anybody else have any ideas to confirm if we are on the right track?

dandrikop commented 1 week ago

@MartinL1983

Indeed, this problem has been reported with https://github.com/magento/magento2/issues/38626. What I added was just some tests with REDIS used for FPC in addition to Files FPC for which the problem was initially reported. I don't know if the problem also occurs if Varnish is used for FPC.

This problem has been routed to be resolved with Magento 2.4.8 version. See AC-11819 at the below link:

https://experienceleague.adobe.com/en/docs/commerce-operations/release/notes/magento-open-source/2-4-8

However, I believe that it should be resolved, as soon as possible, with an official patch for the version 2.4.7 in which it appeared for the first time. It is obvious that multi-stores which are currently on Magento 2.4.6 cannot be upgraded to 2.4.7 due to this serious problem, as a multi-store on Magento 2.4.7 actually works without FPC, at least if FPC is configured with either Files or REDIS.

Webroju commented 1 week ago

@MartinL1983, thanks for the patch, but I see no positive effect from the patch. (NGINX, MAGE_RUN_CODE)

MartinL1983 commented 1 week ago

@Webroju

Did you add it to your composer.json followed by a composer install?

Webroju commented 1 week ago

@MartinL1983 I have not installed it over composer, I have installed like a patch. patch -p1 < filename.patch

MartinL1983 commented 1 week ago

@Webroju

I have never applied a patch that way, so I could not tell you what is wrong.

I always apply patches via composer like this:

"extra": {
    "magento-force": "override",
    "composer-exit-on-patch-failure": true,
    "patches": {
        "magento/framework": {
            "Patch for FPC Identifier on load": "patches/composer/magento/framework/cache/kernel.patch"
        },
    }
}
dandrikop commented 1 week ago

@MartinL1983, @Webroju

I believe that an official patch should become available at the below page:

https://experienceleague.adobe.com/tools/commerce-quality-patches/index.html

I don't think that there is only a small number of multi-store Magento installations around the world. The reason that this issue has not taken significant publicity yet maybe that either a few installations may be upgraded to 2.4.7, or some store owners who have already upgraded to 2.4.7 may have not yet realized that they don't actually have FPC.

dandrikop commented 46 minutes ago

@MartinL1983,

The attributes MAGE_RUN_TYPE and MAGE_RUN_CODE must be part of the hash. I'm using a 3rd party module for Full Page Cache warming on Magento 2.4.6, where the FPC works fine with Magento multi-store, and I can see that the Vary data shown by that module includes the MAGE_RUN_TYPE and MAGE_RUN_CODE. I attached here in a relevant screenshot from Magento 2.4.6:

image

Are you sure that the patch you mention can work with the FPC without any complications in other parts of Magento functionality? I'm just asking because the below patch that was initially issued for this problem includes a lot of changes:

https://github.com/search?q=repo%3Amagento%2Fmagento2+AC-11819&type=commits

On the other hand, this very patch was never included in Magento Quality Patches for Magento 2.4.7.