{"record":{"id":"e5b0fdae8af45122","repo":"redis/jedis","slug":"all-configured-databases-are-unhealthy-cannot-ini","errorCode":null,"errorMessage":"All configured databases are unhealthy. Cannot initialize MultiDbConnectionProvider.","messagePattern":"All configured databases are unhealthy\\. Cannot initialize MultiDbConnectionProvider\\.","errorType":"exception","errorClass":"JedisConnectionException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/mcf/MultiDbConnectionProvider.java","lineNumber":463,"sourceCode":"        log.debug(\"No health check configured for database {}, defaulting to HEALTHY\", endpoint);\n      }\n\n      ConnectionInitializationContext evalCtx = new ConnectionInitializationContext(databaseMap,\n          healthStatusManager);\n      Decision d = evalCtx.conformsTo(policy);\n      log.debug(\"Policy evaluation after {}: {}\", endpoint, d);\n      if (d == Decision.SUCCESS) {\n        return selectBestAvailableDatabase(sortedDatabases);\n      }\n      if (d == Decision.FAIL) {\n        throw new JedisConnectionException(\n            \"Initialization failed due to initialization policy: \" + evalCtx);\n      }\n      // else CONTINUE -> move to the next pending endpoint\n    }\n\n    // All databases are unhealthy\n    throw new JedisConnectionException(\n        \"All configured databases are unhealthy. Cannot initialize MultiDbConnectionProvider.\");\n  }\n\n  /**\n   * Selects the best available (healthy) database based on weight priority.\n   * @param sortedDatabases the list of databases sorted by weight in descending order\n   * @return the highest-weighted healthy database\n   * @throws JedisConnectionException if no healthy database is available\n   */\n  private Database selectBestAvailableDatabase(\n      List<Map.Entry<Endpoint, Database>> sortedDatabases) {\n    log.info(\"Selecting initial database from {} configured databases\", sortedDatabases.size());\n\n    // Select first healthy database in weight order\n    for (Map.Entry<Endpoint, Database> entry : sortedDatabases) {\n      Endpoint endpoint = entry.getKey();\n      Database database = entry.getValue();\n","sourceCodeStart":445,"sourceCodeEnd":481,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/mcf/MultiDbConnectionProvider.java#L445-L481","documentation":"After iterating every configured database in weight order and waiting for each health check, if the InitializationPolicy never returned SUCCESS (typically because no database ever reported healthy), MultiDbConnectionProvider throws JedisConnectionException stating all configured databases are unhealthy. The client cannot select an active database, so initialization fails.","triggerScenarios":"Building a MultiDbClient where every endpoint in databaseMap ends up with an unhealthy HealthStatus after waitForHealthStatus completes for all of them, and the initialization policy evaluates to CONTINUE for each endpoint until the loop exhausts the list.","commonSituations":"Entire Redis fleet down or unreachable (network outage, VPN not connected); all endpoints misconfigured (bad hosts/ports or wrong credentials causing health check failures); security group/firewall blocking health check ports; Redis persisting in a state that fails the health probe.","solutions":["Test each configured endpoint from the application host with redis-cli -h <host> -p <port> PING and fix connectivity.","Verify credentials (username/password) and TLS settings in each database entry of MultiDbConfig.","Wait for the Redis fleet to recover or fix the environment (DNS, firewall, VPN) before restarting the client.","Review health check configuration (endpoints used for probing, timeouts) to rule out systemic false negatives."],"exampleFix":"// before\n.database(MultiDbConfig.databaseConfigBuilder()\n    .connectionConfig(RedisURI.builder().host(\"redis-primary.internal\").port(6379).build())\n    .weight(1.0f).build()) // host unreachable from app env\n// after — verify host reachable, or use correct internal DNS\n.database(MultiDbConfig.databaseConfigBuilder()\n    .connectionConfig(RedisURI.builder().host(\"redis-primary.prod.svc.cluster.local\").port(6379).build())\n    .weight(1.0f).build())","handlingStrategy":"retry","validationCode":"// Check all endpoints before constructing the provider\nboolean anyHealthy = config.getDatabases().stream().anyMatch(db -> {\n  try (Jedis p = new Jedis(db.getHost(), db.getPort())) {\n    return \"PONG\".equals(p.ping());\n  } catch (Exception e) { return false; }\n});\nif (!anyHealthy) throw new IllegalStateException(\"No Redis endpoint reachable\");","typeGuard":null,"tryCatchPattern":"int attempts = 0;\nwhile (attempts++ < 5) {\n  try { client = MultiDbClient.builder().multiDbConfig(cfg).build(); break; }\n  catch (JedisConnectionException e) {\n    Thread.sleep(2000L * attempts); // retry: fleet may be recovering\n  }\n}","preventionTips":["Deploy against a fleet with redundancy so 'all unhealthy' requires a total outage.","Alert on Redis health so the fleet is restored before clients restart.","Validate DNS/firewall/VPN paths from the app environment in CI smoke tests.","Double-check that all endpoint URIs point to the right environment (staging vs prod)."],"tags":["redis","jedis","connection","initialization","multi-db","health-check","network"],"backgroundTag":"connection-refused","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}