Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Cache] ArrayAdapter serialization exception does not clean $expiries #60121

Copy link
Copy link
Closed
@bastien-wink

Description

@bastien-wink
Issue body actions

Symfony version(s) affected

7.3 (since 5.0)

Description

In ArrayAdapter.php:339, if $value contains a Closure, an Exception is triggered and $this->values get cleaned.

  try {
      $serialized = serialize($value);
  } catch (\Exception $e) {
      unset($this->values[$key], $this->expiries[$key], $this->tags[$key]);
      $type = get_debug_type($value);
      $message = \sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage());
      CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]);

      return null;
  }

$this->expiries is used in ArrayAdapter.php:300 to determine cache hit. If hash is found in $this->expiries but missing in $this->keys it generate a NOTICE.

How to reproduce

Use this Doctrine configuration with an Entity containing a Closure.

    orm:
        entity_managers:
            default:
                second_level_cache:
                    enabled: true
                    regions:
                        array_persistence:
                            # Store with Cache/Adapter/ArrayAdapter
                            cache_driver: pool

Possible Solution

On serialize($value); catch Exception, clean expiries with unset.

Incoming Pull Request.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.