-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Magento 2.4 critical load of RAM triggering OOM killer due to CSP module 100.4.0 #29964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @onepack. Thank you for your report.
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
For more details, please, review the Magento Contributor Assistant documentation. Please, add a comment to assign the issue:
🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
I see it trying to allocate a 67MB CSP policy!!! I'm going to run with CSP module disabled for a while and see if that helps |
@gwharton a quick workaround is to disable the CSP module. |
Seemed to be something to do with the BlockCache with the limited debugging I was able to do before throwing one's hands in the air and disabling CSP. |
Hi @AlexMaxHorkun. Thank you for working on this issue.
|
I was not able to reproduce this locally with 1200+ products and dozens of categories. Perhaps this issue can only occur on a heavily resource limited setup. However I can see that there is a room for improvement performance wise in CSP implementation and it will be addressed in the next 2.4.x release |
eeeeekkkkk :( 67MB of CSP headers being allocated is not something that should be happening on any machine, let alone a resource starved one. There is something wrong in the block cache/CSP area it seems. I know when mine was failing, none of the hashes from the secure inline scripts were making it into the CSP headers either. I am using varnish, I don't know if that matters. |
Also, it only seems to occurr at random times. I can let my site run for days with no problem, then all of a sidden, something triggers it and I am getting out of memory errors and apache is reporting random 503's to varnish. If I then clear cache, it runs fine again for a few days, then bang! I have had no issues whatsoever since disabling CSP. I for one, don't think module-csp is ready for production use. |
This just happened to me on a second store. Redis usage grows to 14 GB in less than 24 hrs in a store with moderate traffic.
And it's always huge. Prior to M2.4.0, the stores could run just fine without The real problem is not the size, the real problem is continues insertion of varying hash data(?). Because only that would explain |
Maybe the following patch can help: 1767ab8 (which is being mentioned in magento/magento-cloud-patches#44) We had some Redis OOM issues on at least two Magento 2.3.5 shops even with the CSP module disabled. This patch seems to fix the OOM issue (although we've only had it running for a couple of days, so not 100% sure yet) It's probably a workaround for the issue described in here, there seems to be a deeper underlying issue if I understand the comments correctly. |
Technically speaking, everyone should set up some memory limit in Redis configuration to avoid OOM altogether. |
I'm seeing this issue too, disabling CSP caused me issues, I've had to setup a cron job to clear the cache every 6 hours!! |
An incredibly high amount of keys is being inserted for normal cache on Magento 2.4 I have a redis instance where cache and full page cache are shared and the normal cache endlessly growing eventually makes the fullpage cache useless since those keys get evicted since it runs out of its maxmemory limit. It also appears that cache:clean does not clean those keys up. Only flushing the redis db helps... |
I can confirm this issue without Redis on Magento 2.4.1 Now with file cache the hard drive gets eaten and we're left with:
Yes, even 8 GB of RAM for PHP is not enough to process. I assume that the foreach loop is just huge for whatever reason or whatever calls the save() method is a big loop.
@AlexMaxHorkun Our server is not at all resource limited with dedicated 16 vCPU, 64 GB of RAM and 160 GB SSD by the way. |
@nathanjosiah 2.4.2? Did you mean 2.4.1 which is "generally available" since yesterday? Else just enlighten me 😁 |
@Morgy93 Apologies, I deleted my comment. I meant to say 2.4.1 but then I realized the fixes will not be available until 2.4.2 |
However, somebody could potentially test using |
All I can see right now is this one 047629a#diff-f82a4c282711708e05d2f1db5f2f2369e2533e5bfb184b3f71db21a5756eafaf from 21 days ago. Current workaround is to |
Hi, Firstly thanks for all of this, it's a problem that's been driving me nuts. Is there an easy workaround or easy way to clear the issue on 2.4.0? I've been monitoring the php error log and then reindexing/flushing which seems to make it go away until next time, which could be an hour but it's getting more frequent. Any help much appreciated. |
@stevenculshaw Have you tried applying the patch listed in comment #29964 (comment) I have been running with that patch on 2.4.1 with no problems. I don't know if it will apply cleanly on 2.4.0, but theres only one way to find out! |
Yeah tried applying to 2.4.0 and just got a mash of errors so must be dependent on something else in 2.4.1. Guess the route is update to 2.4.1 and then try patching the code in from 2.4.2 again. I just wondered if there was anything anyone had found to help with the symptoms while I work out how to do that on the busiest shopping weekend of the year. |
someone mentioned disabling module-csp, is that a really bad idea? |
not at all. unless you have configured it otherwise, CSP only runs in report only mode, so it doesn't provide ANY extra security unless you set it up to. So if you havent configured any additional policies for your site, or changed it to enforcing, then the only thing it is giving you is the crashes. Go ahead and disable it. You won't see any negative effects from disabling it. I did check that patch against 2.4.0 and it should apply cleanly. But like you say, for a busy shopping period......... get it disabled if its causing you issues :) |
Thanks for that clarification Graham, much appreciated, will give it a go |
For what it's worth, @gwharton your patch contains much more than the changes I mentioned above in #29964 (comment) which is probably why it isn't applying cleanly for @stevenculshaw |
Yes, the patch contains much more than @nathanjosiah mentioned and I was a little confused about it, but I'd like to quickly confirm that the patch works wunderfully on 2.4.1 Finally fixed, thanks all! 👏 |
@nathanjosiah As far as I can see, everything in the patch I listed (which was the whole commit by the core team) is needed to support the few lines you posted in your comment. It adds support for the merger that is in your comment. I also deployed 2.4.0, manually made the same changes as in the patch i posted, then diff'd against a vanilla 2.4.0 install, and compared the diffs to the original patch, and they are identical, so the patch SHOULD apply cleanly on 2.4.0. |
Hey all, temporarily disabling the csp module has provided valuable breathing-space, not a single error logged since. I've made a scratch copy of the site and later I will try the patch again on that and see what happens. Thanks all for your help! |
Just to add a bit of context to this: I just had this happen, both the cache growing to huge sizes and the out of memory on front end pages. On my production site using external server level full page cache (livemage, in my case), the issue happens. So either disabling CSP or switching to the (slower, granted) internal cache are options to mitigate until 2.4.2 is released. |
I have the same problem but am a bit confused how to patch. Have a 2.4.1. site Could someone post how this should be changed and if any other changes need to be made please. `<?php
namespace Magento\Csp\Model\Collector; use Magento\Csp\Api\Data\PolicyInterface; /**
|
Can anyone please verify that this issue is fixed in M 2.42 ? Can anyone advise please? |
@caricell: I have access to the pre-release of 2.4.2 and can confirm that the commit @gwharton linked to before is included in there, but indeed it ( |
Hello Pieter and thanks so much for your response!
This OOM issue has been plaguing myself and my developer since we upgraded to 2.41.
If you could let me know what you find out about why it was not included in the release notes, I would certainly appreciate it!!!
Thank you!
Larry
From: Pieter Hoste <[email protected]>
Sent: Tuesday, February 2, 2021 2:51 PM
To: magento/magento2 <[email protected]>
Cc: caricell <[email protected]>; Mention <[email protected]>
Subject: Re: [magento/magento2] Magento 2.4 critical load of RAM triggering OOM killer due to CSP module 100.4.0 (#29964)
@caricell <https://github.com/caricell> : I have access to the pre-release of 2.4.2 and can confirm that the commit @gwharton <https://github.com/gwharton> linked to before <#29964 (comment)> is included in there, but indeed it (MC-37799) doesn't appear to be included in the release notes of 2.4.2 which is strange.
I've alerted the person in charge of the release notes, hopefully she'll be able to figure out why it's not included yet.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#29964 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/ASWO2ZHNVTROQMFZ2K2EJ5DS5BJRXANCNFSM4RCTZGCA> . <https://github.com/notifications/beacon/ASWO2ZHNID2BQQU757LJXCLS5BJRXA5CNFSM4RCTZGCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFYBLU2I.gif>
|
Thank you so much! |
We've been running 2.4.2. Can confirm this issue is resolved. |
Thank you as well, laguna. I guess they just missed it in the release notes. |
I got confirmation that it will be included in the release notes soon 🙂 . Thanks for the heads-up! |
Thanks again!
Larry
From: Pieter Hoste <[email protected]>
Sent: Tuesday, February 2, 2021 3:13 PM
To: magento/magento2 <[email protected]>
Cc: caricell <[email protected]>; Mention <[email protected]>
Subject: Re: [magento/magento2] Magento 2.4 critical load of RAM triggering OOM killer due to CSP module 100.4.0 (#29964)
I got confirmation that it will be included in the release notes soon 🙂
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#29964 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/ASWO2ZARB33MSKCDL5XZ4DDS5BMD7ANCNFSM4RCTZGCA> . <https://github.com/notifications/beacon/ASWO2ZCHE5O6XR4BU24OX5DS5BMD7A5CNFSM4RCTZGCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFYBPSOY.gif>
|
Nope. I just upgraded to 2.4.2-p1, still the same issue on multiple environments and cache types (redis and file storage cache) |
Really. It was fixed in 2.4.2. it was missed from the release notes though but the fix was there. I've been running since 2.4.2 with csp enforcing with no issues. |
Yup, I created 2 threads about this on stackoverflow. I'm not sure how yours is working, but mine is an upgrade from 2.3.3 without any other modifications. https://magento.stackexchange.com/questions/340934/magento-2-4-2-p1-redis-cache-full |
I wonder if there is a separate issue. The commit 047629a#diff-f82a4c282711708e05d2f1db5f2f2369e2533e5bfb184b3f71db21a5756eafaf definately fixed my issue and has been present since 2.4.2 |
I definitely have this in my vendor folder and both files are exact copies from the commit. As soon as I disabled the CSP plugin and flushed the cache it started to work right away. I ran Search Indexing multiple times that day and the only time it stopped filling the Redis container RAM was after disabling the CSP plugin. |
Preconditions (*)
Steps to reproduce (*)
Expected result (*)
Actual result (*)
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
We found out via SSH top that the RAM consumption was peaking during the category generation on the frontend (from uncachd to cached).
First we thought it was a Redis issue because 9 out of ten times the page would look broken like we have seen in the M1 days because of a Redis issue.
But actually "the broken page layout" was the result of PHP running out of memory.
The result would get cached and stay in the cache until the redis cache was cleared.
After a lot of digging I found the source of the issue in:
vendor/magento/module-csp/Model/BlockCache.php
Under the function: load($identifier)
This function uses a crazy amound of RAM.
Quick workaround is disabling the module to keep the shop RAM usage healthy.
The log errors show that this function is causing issues.
I copied the log errors from another user running into the same issue:
[Mon Aug 17 19:40:50.052935 2020] [php7:error] [pid 16932:tid 140669993522944] [client 127.0.0.1:40654] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 48238592 bytes) in /var/www/html/vendor/magento/framework/Serialize/Serializer/Json.php on line 24
[Mon Aug 17 19:40:51.592030 2020] [php7:error] [pid 16933:tid 140670169769728] [client 127.0.0.1:40666] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/vendor/magento/module-csp/Model/BlockCache.php on line 108
[Mon Aug 17 19:41:12.706529 2020] [php7:error] [pid 17146:tid 140670127806208] [client 127.0.0.1:40702] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/vendor/magento/module-csp/Model/BlockCache.php on line 108
[Mon Aug 17 19:41:12.740424 2020] [php7:error] [pid 17146:tid 140670127806208] [client 127.0.0.1:40702] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 122880 bytes) in Unknown on line 0
[Mon Aug 17 19:41:24.887257 2020] [php7:error] [pid 16939:tid 140670111020800] [client 127.0.0.1:40798] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 4096 bytes) in /var/www/html/vendor/magento/module-csp/Model/BlockCache.php on line 78
[Mon Aug 17 19:41:24.913106 2020] [php7:error] [pid 16939:tid 140670111020800] [client 127.0.0.1:40798] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 65536 bytes) in Unknown on line 0
[Mon Aug 17 19:41:39.997127 2020] [php7:error] [pid 16933:tid 140670152984320] [client 127.0.0.1:40904] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/vendor/magento/module-csp/Model/BlockCache.php on line 108, referer: http://ip-of-my-ec2-instance:80/
[Mon Aug 17 19:41:40.030659 2020] [php7:error] [pid 16933:tid 140670152984320] [client 127.0.0.1:40904] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 40960 bytes) in Unknown on line 0, referer: http://ip-of-my-ec2-instance:80/
[Mon Aug 17 19:42:08.849538 2020] [php7:error] [pid 17146:tid 140670111020800] [client 127.0.0.1:41016] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/vendor/magento/framework/Serialize/Serializer/Json.php on line 42
[Mon Aug 17 19:42:08.865389 2020] [php7:error] [pid 17146:tid 140670111020800] [client 127.0.0.1:41016] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 32768 bytes) in Unknown on line 0
[Mon Aug 17 19:44:23.245570 2020] [php7:error] [pid 17146:tid 140670027093760] [client 127.0.0.1:41798] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/vendor/magento/framework/Serialize/Serializer/Json.php on line 42, referer: https://www.google.com/
[Mon Aug 17 19:44:23.312177 2020] [php7:error] [pid 17146:tid 140670027093760] [client 127.0.0.1:41798] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 45056 bytes) in Unknown on line 0, referer: https://www.google.com/
[Mon Aug 17 19:44:29.224653 2020] [php7:error] [pid 16939:tid 140670052271872] [client 127.0.0.1:41742] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/vendor/magento/module-csp/Model/BlockCache.php on line 108
[Mon Aug 17 19:44:29.264725 2020] [php7:error] [pid 16939:tid 140670052271872] [client 127.0.0.1:41742] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 90112 bytes) in Unknown on line 0
[Mon Aug 17 19:44:34.254009 2020] [php7:error] [pid 17146:tid 140670043879168] [client 127.0.0.1:41688] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/vendor/magento/module-csp/Model/BlockCache.php on line 108
[Mon Aug 17 19:44:34.294439 2020] [php7:error] [pid 17146:tid 140670043879168] [client 127.0.0.1:41688] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 36864 bytes) in Unknown on line 0
[Mon Aug 17 19:44:40.650547 2020] [php7:error] [pid 17146:tid 140670010308352] [client 127.0.0.1:41882] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/vendor/magento/framework/Serialize/Serializer/Json.php on line 42
[Mon Aug 17 19:44:40.690603 2020] [php7:error] [pid 17146:tid 140670010308352] [client 127.0.0.1:41882] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 49152 bytes) in Unknown on line 0
[Mon Aug 17 19:44:49.990225 2020] [php7:error] [pid 16939:tid 140670144591616] [client 127.0.0.1:42006] PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 33554440 bytes) in /var/www/html/vendor/magento/module-csp/Model/Collector/DynamicCollector.php on line 31
The text was updated successfully, but these errors were encountered: