statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
4.08k stars 533 forks source link

Memory leak due to cache tag usage #9737

Open bellevue7k-user opened 8 months ago

bellevue7k-user commented 8 months ago

Bug description

Only the page with the code blog below gives this error on average once a week.

Allowed memory size of 536870912 bytes exhausted (tried to allocate 169795472 bytes) {"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Allowed memory size of 536870912 bytes exhausted (tried to allocate 169795472 bytes) at /home/web...../vendor/laravel/framework/src/Illuminate/Cache/FileStore.php:84)

Then, clearing the Application Cache and Content Stache fixes it. I think that should be here an usage error . Because it is just an team page and does not consist of very large data.

Relevant code:

<div class="l-team__cards">
      {{ collection:team sort="last_name" as="teammember" }} 
          {{ teammember }}
              {{ cache key="team_cache_{id}" }}
                  {{ partial:partials/teamcard }}
              {{ /cache }}
          {{ /teammember }}
      {{ /collection:team }}
</div>

cache clearing:

 Event::listen(function (EntrySaved $event) {
      if ($event->entry->collectionHandle() === 'team') {
          Cache::forget('team_cache_'.$event->entry->id);
      }
  });

I used cache tags in many different ways. For example, I used scope and for instead of key, but the result is still the same.

How to reproduce

The page where only the {{ cache tag }}  is used gives this error on average once a week.

Logs

Allowed memory size of 536870912 bytes exhausted (tried to allocate 169795472 bytes) {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Allowed memory size of 536870912 bytes exhausted (tried to allocate 169795472 bytes) at /home/web...../vendor/laravel/framework/src/Illuminate/Cache/FileStore.php:84)

Environment

Environment
Application Name: Wep Page Name
Laravel Version: 10.30.1
PHP Version: 8.2.16
Composer Version: 2.5.5
Environment: production
Debug Mode: OFF
URL: .........com
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: sendmail
Queue: sync
Session: file

Statamic
Addons: 2
Antlers: runtime
Stache Watcher: Disabled
Static Caching: Disabled
Version: 4.53.0 PRO

Statamic Addons
steadfastcollective/statamic-csv-exporter: 2.2.1
takepart-media/statamic-oreos: 1.3.0

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

None

Additional details

No response

stuartcusackie commented 23 hours ago

I don't know if this is related but one of my sites just started crashing. It was recently upgraded to the latest version of Statamic.

Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) at /home/forge/mysite.ie/vendor/laravel/framework/src/Illuminate/Cache/FileStore.php:316)

I don't use the cache tag, but I do use the @nocache blade directive.

I redeployed my site and it works now - my deployment script clears some of the cache but I'm not sure which one would affect this.

Actually... Maybe this recent pull request fixes it. I'll update to the latest version and see if it happens again.