-
Notifications
You must be signed in to change notification settings - Fork 629
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
[4.x]: unserialize() Error at offset #13164
Comments
That Yii caching code looks like it should be more error tolerant when unserializing whatever the cause of this is, no? |
The only cache-related thing Craft does when saving an entry is invalidate existing caches for the element, which doesn’t actually touch the element caches at all—only cache tag caches are updated, which are very small cache files that only contain a timestamp. So whatever caused this corruption, it wasn’t caused by saving an entry twice in quick succession (at least directly). That cache looks like it contains a serialized field layout. Probably from an entire entry getting cached? It’s generally not a good idea to cache instantiated PHP objects unless the object’s class was clearly coded for it (e.g. with So you should probably try to track down why the field layout/entry is getting cached in the first place, and cache the specific data you need from it instead.
Yeah, wrapping that code in a try/catch wouldn’t hurt. Just PR’d that change: yiisoft/yii2#19827 |
This isn't something I'm doing anywhere (in my own code at least), so maybe it's one of those plugins. I'll see if I can track down the culprit.
Great, thank you! |
Sorry Brandon, I disabled plugins in the config ( |
Went back to Craft |
Hm, I’m not seeing the same behavior on my end. Try the following:
There should be a stack trace along with the log message. Can you post it here? If the exception isn’t getting logged, maybe some other object is getting cached that contains the field layout. You could change the code to this:
There could be additional noise with that code, though. |
The second method identified
However, I uninstalled that from
I had project config disabled, but I tried it with it enabled (after making sure the project config yaml was rebuilt from the database) - and the large cache file is still created with the stack trace the same. |
Any chance you can send a database backup and your Composer files over to [email protected]? |
I've sent that over, let me know if you need anything else. Many thanks for taking a look. |
Looks like I was wrong, there aren’t any entries/field layouts getting cached. Just the field layout settings for an entry type, which is expected. Still, saving an entry won’t touch your project config, so I don’t see how double-saving an entry would cause the project config cache to become corrupted. Probably just a coincidence. The Yii PR was rejected since So the real issue here is that Craft is being a little overzealous when it comes to error reporting. I’ve just toned that down for the next release. Going forward, PHP warnings and notices will no longer halt execution unless Dev Mode is disabled. |
Thank you, that looks like the best solution possible for now. For the record, this happened on three occasions when editing the same entry; each time the corrupted cache file had a modified date exactly 1 day after the time of the error - suggesting the file was indeed touched during the save process for the entry, inexplicable though that seems! |
4.4.10 is out with the warning and notice reporting changes. |
Would you mind reopening this issue, if appropriate? We're seeing problems with another project where the project config cache file (always saved at |
The cache duration also seems short - one day. Why not a year? Regeneration of the cache is triggered by any request, so given the potential for that file to be corrupted we could see intermittent errors on the front end for an unlucky user. |
@croxton The cache stores the project config data verbatim, so it would only grow that large if your project config itself is that large. The best way to reduce that would be to simplify your content model. (We’re working to make that more doable in Craft 5.)
Not a bad idea. Would you mind loading your
It just uses the default cache duration, which probably makes sense to be 24h by default, considering the variety of things that get cached. But I just added a way to override it from use craft\helpers\App;
use craft\helpers\ConfigHelper;
return [
'components' => [
'projectConfig' => fn() => Craft::createObject([
'cacheDuration' => ConfigHelper::durationInSeconds('P1Y'),
] + App::projectConfigConfig()),
],
]; |
@brandonkelly thank you for allowing the cache duration to be configurable - that should help a lot. Interestingly, looking at the largest files the yaml for Verbb's Hyper fields seems excessively verbose compared to other field types. |
@brandonkelly If you are able to break the PC cache up into smaller files I think that could actually prove quite a crucial optimisation as the complexity of Craft fields (such as Hyper) increases. In terms of content model the sites in question are actually not as complex as other sites we have built (that remain on Craft 3). |
I take it the Hyper field(s) live within |
Yes that's right. |
Craft 4.5.0 is out with the |
What happened?
Description
The
storage/runtime
cache becomes corrupted when saving an entry using the keyboard (control-s
) when Craft is in the middle of auto-saving the entry. The entire site is broken until the cache is deleted.This problem seems to have emerged with the latest (or a recent) version of Craft, but I may have just missed it previously.
Steps to reproduce
Expected behavior
Manual saving should be disabled during autosave, or the manual save should be queued.
Actual behavior
Entire site breaks!
Craft CMS version
4.4.9
PHP version
8.1.10 (MAMP Pro on OSX)
Operating system and version
OSX
Database type and version
mysql 5.7.34 (MAMP Pro on OSX)
Image driver and version
No response
Installed plugins and versions
Calendar Links
Control Panel JS
Element API
Environment Label
Feed Me
Field Manager
Freeform
Google Maps
Help Links
Hyper
Image Resizer
Imgixer
Matrix Mate
Navigation
Postmark
Read Time
Redactor
SEOmatic
Servd Assets & Helpers
Sherlock
Similar
Sprig
Super Table
Table Maker
Template Select
The text was updated successfully, but these errors were encountered: