#4755·jedis

MultiDbClient never recovers after total outage: health check scheduler dies when failover has no candidate

Author: ggivoCreated Sep 28, 2026Updated Sep 28, 2026
Labelsbug

Expected behavior

After all databases of a MultiDbClient become unavailable long enough that commands fail with JedisPermanentlyNotAvailableException, the client should resume automatically once the active database is healthy again. Health checks should keep running for as long as the provider is open.

Actual behavior

If the active database turns unhealthy at a moment when no other database is healthy, its health checks silently stop running, its status stays frozen at UNHEALTHY, and the client never recovers — even after every database is back — until the application is restarted.

Root cause

onHealthStatusChange runs synchronously inside the health check scheduler task:

HealthCheckImpl.healthCheck()   // scheduleAtFixedRate task
  -> safeUpdate -> notifyListeners
    -> MultiDbConnectionProvider.onHealthStatusChange
      -> switchToHealthyDatabase -> handleNoHealthyDatabase
        -> throws JedisTemporarilyNotAvailableException

Nothing catches it, so it escapes the scheduleAtFixedRate runnable — which cancels all subsequent executions and buries the throwable in a ScheduledFuture nobody reads. No log, no further checks, status frozen. The catch (TimeoutException | ExecutionException) inside healthCheck() doesn't help: it only guards the probe's future.get(); the listener call happens after it, on the scheduler thread.

Reproduction

MultiDbConnectionProviderTest#userCommand_afterPermanent_activeDatabaseHealthyAgain_autoRecovers_healthCheckDriven (#4756): two databases with test-controlled health checks, both turn unhealthy → JedisPermanentlyNotAvailableException; the active one turns healthy again → the client never recovers. Fails before the fix, passes after.

Impact / workaround

Affects all versions with the mcf package (7.0.0 through master).

Fix (#4756)

  1. MultiDbConnectionProvider.onHealthStatusChange: catch the JedisFailoverException from switchToHealthyDatabase — a health-event listener has no caller that can act on it; log and return.
  2. HealthCheckImpl: run the scheduled task through a guard that logs any RuntimeException instead of letting it cancel monitoring.

After the fix the client recovers automatically once the active database (or a higher-weight one, via failback) is healthy again.

Notes

Recovery scope after the fix: if, after failover attempts are exhausted and commands fail with JedisPermanentlyNotAvailableException, only a lower-weight database becomes healthy while the active one is still down, the client does not switch to it automatically — nothing triggers a failover (the circuit breaker doesn't trip on the dead endpoint's errors at low traffic, and failback only promotes databases with a weight higher than the active one's). A manual setActiveDatabase() is required in that case. This is existing, intended failback behavior — not part of this bug — and is documented by the companion requiresManualSwitch test in #4756.