You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#47003 added support for using multiple Redis Sentinel hosts. However, if the first Sentinel host cannot be resolved (e.g. because a DNS name cannot be resolved or because the server is not responding), a \RedisException is thrown and the code does not try to connect to the other Sentinel hosts.
In this code block, it tries to connect to Sentinel and resolve the master address:
If you have a Redis Sentinel instance running, just add the host as second (or later) and observe that nothing is written into your Redis instance.
If you do not have a Redis Sentinel instance running, the same behavior can be verified by adding an exit statement after the if-block from the code snippet above. The code will not terminate, since it never reaches that statement.
Possible Solution
The call to getMasterAddrByName() could be wrapped in a simple try...catch to suppress any error.
I am not sure if there are valid errors that should not be caught. In that case, the exception message could be checked for specific errors.
Additional Context
I haven't investigated how this behaves with Relay.
The text was updated successfully, but these errors were encountered:
…irst one is not resolvable (digilist)
This PR was merged into the 5.4 branch.
Discussion
----------
[Cache] fix using multiple Redis Sentinel hosts when the first one is not resolvable
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix#51570
| License | MIT
| Doc PR |
See ticket #51570 for details on this bugfix.
As mentioned in the ticket, I am not sure if it's wise to catch all exceptions or if it would be better to only check for specific ones. But since I cannot think about any reasons other than an unreachable host to raise any exception, I decided to catch all exceptions for now.
Commits
-------
578a152 [Cache] fix using multiple Redis Sentinel hosts when the first one is not resolvable
Symfony version(s) affected
>= 5.4
Description
#47003 added support for using multiple Redis Sentinel hosts. However, if the first Sentinel host cannot be resolved (e.g. because a DNS name cannot be resolved or because the server is not responding), a
\RedisException
is thrown and the code does not try to connect to the other Sentinel hosts.In this code block, it tries to connect to Sentinel and resolve the master address:
symfony/src/Symfony/Component/Cache/Traits/RedisTrait.php
Lines 228 to 232 in 64303aa
The call to
getMasterAddrByName()
is throwing theRedisException
and will prevent any attempt to connect to other Sentinel hosts.This exception is thrown if the hostname cannot be resolved:
And this exception if the server port is invalid (no previous exception in this case):
How to reproduce
You could use this environment variable / DSN to observe the behavior with invalid host names at first and valid host names afterwards:
If you have a Redis Sentinel instance running, just add the host as second (or later) and observe that nothing is written into your Redis instance.
If you do not have a Redis Sentinel instance running, the same behavior can be verified by adding an
exit
statement after the if-block from the code snippet above. The code will not terminate, since it never reaches that statement.Possible Solution
The call to
getMasterAddrByName()
could be wrapped in a simple try...catch to suppress any error.I am not sure if there are valid errors that should not be caught. In that case, the exception message could be checked for specific errors.
Additional Context
I haven't investigated how this behaves with Relay.
The text was updated successfully, but these errors were encountered: