Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Cache] PHP Warning in case of omited exception while trying to delete cache key for Redis adapter #45325

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

Closed
andrew-demb opened this issue Feb 5, 2022 · 0 comments

Comments

@andrew-demb
Copy link
Contributor

andrew-demb commented Feb 5, 2022

Symfony version(s) affected

5.4 (probably 4.4 also)

Description

Our application at some moment was connected to the Redis replica server (accidentally) for the cache.

When we are tried to delete the cache key - Redis throws an exception RedisException - READONLY You can't write against a read-only replica. (which is pretty OK - symfony/cache should catch this error and suppress).

But application written many PHP warnings to the logs - PHP message: PHP Warning: Undefined property: Symfony\Component\Cache\Adapter\RedisTagAwareAdapter::$namespace in /.../vendor/symfony/cache/Adapter/RedisTagAwareAdapter.php on line 168

How to reproduce

  1. Connect to Redis replica server
  2. Use \Symfony\Component\Cache\Adapter\RedisTagAwareAdapter::deleteItems()

Possible Solution

Sorry, symfony/cache is pretty complex to me (heavy usage of traits, multi-level class hierarchy, universal redis adapters for all known drivers), so I can't suggest a fix (or at least an accurate test case).

Need to try to avoid using private trait property \Symfony\Component\Cache\Traits\AbstractAdapterTrait::$namespace from \Symfony\Component\Cache\Adapter\RedisTagAwareAdapter, or find a way to make this property accessible in this context.

Additional Context

PhpStorm mentions issue about inappropriate using trait private property in 2 places (linked from 4.4 branch):

@andrew-demb andrew-demb added the Bug label Feb 5, 2022
nicolas-grekas added a commit that referenced this issue Feb 8, 2022
This PR was merged into the 4.4 branch.

Discussion
----------

[Cache] fix error handling when using Redis

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #45325
| License       | MIT
| Doc PR        | -

Spotted while working on #45313

I won't be able to add tests here, the situations are too edgy.

Commits
-------

3c59e0f [Cache] fix error handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants