Connection refuse in PhpRedis when sentinel/redis are down

Created on 5 August 2020, over 4 years ago
Updated 31 July 2024, 5 months ago

Problem/Motivation

When using redis module with PhpRedis with for example 3 redis server (1 master, 2 slaves) and sentinel.

If the first server in the list set in settings.local.php is down, then the website return a Fatal error: connection refuse
at line 83 in redis/src/Client/PhpRedis.php

my settings.local.php look like this:

$settings['redis.connection']['host']      = ['192.168.0.1:26379', '192.168.0.2:26379', '192.168.0.3:26379'];

Steps to reproduce

Use redis module with PhpRedis and 3 redis server with sentinel (X, Y, Z).
X, Y, Z are the IP of the 3 servers.

Set in your settings.local.php, the 3 servers like this:

$settings['redis.connection']['host']      = ['X:26379', 'Y:26379', 'Z:26379'];

Ssh to server X and stop sentinel and redis, then try to access your website.
The website encountered an unexpected error. Please try again later.

In the log you can see that the error is in file "modules/contrib/redis/src/Client/PhpRedis.php" at line 83:

$success = $client->connect($host, $port, 0.5);

Proposed resolution

Add a try / catch around this client->connect to avoid the all website to went down.
Proposed code solution:

        try {
          $success = $client->connect($host, $port, 0.5);
        }
        catch (\Exception $e) {
          continue;
        }
🐛 Bug report
Status

Needs review

Version

1.4

Component

Code

Created by

🇩🇪Germany Tomefa Dresden

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024