{"record":{"id":"0bffdcc1d28997fd","repo":"redis/jedis","slug":"initialization-failed-due-to-initialization-policy-0bffdc","errorCode":null,"errorMessage":"Initialization failed due to initialization policy: ${evalCtx}","messagePattern":"Initialization failed due to initialization policy: (.+?)","errorType":"exception","errorClass":"JedisConnectionException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/mcf/MultiDbConnectionProvider.java","lineNumber":456,"sourceCode":"      // Check if health checks are enabled for this endpoint\n      if (healthStatusManager.hasHealthCheck(endpoint)) {\n        log.info(\"Health checks enabled for {}, waiting for result\", endpoint);\n        // Wait for this database's health status to be determined\n        statusTracker.waitForHealthStatus(endpoint);\n      } else {\n        // No health check configured - assume healthy\n        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) {","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/mcf/MultiDbConnectionProvider.java#L438-L474","documentation":"While waiting for initialization, MultiDbConnectionProvider iterates the configured databases in descending weight order and, after each endpoint's health status resolves (statusTracker.waitForHealthStatus), re-evaluates the InitializationPolicy. If that re-evaluation returns Decision.FAIL, initialization is aborted with JedisConnectionException. Unlike error 170 (immediate fail), this one fires after waiting for at least one endpoint's health check result, meaning the resolved statuses definitively violate the policy.","triggerScenarios":"Building a MultiDbClient where, after waitForHealthStatus(endpoint) returns for one or more endpoints, ConnectionInitializationContext.conformsTo(policy) returns FAIL — e.g. the first (highest-weight) database's health check resolves as unhealthy and the policy (such as 'all active' or a minimum count) is already violated at that point.","commonSituations":"Primary Redis is down at application startup and the policy demands all/most databases healthy; health check auth failures (wrong password) marking endpoints unhealthy; health check timeouts due to network partition; too aggressive health check settings causing false unhealthy status.","solutions":["Check the per-endpoint health statuses in the exception's ConnectionInitializationContext message to identify which database failed.","Restore connectivity/credentials for the unhealthy endpoints; confirm with redis-cli PING from the app host.","Choose a less strict InitializationPolicy (e.g. failover policy that only requires one healthy database) in MultiDbConfig.","Increase health check timeouts/intervals so slow-starting Redis instances are not marked unhealthy during initialization."],"exampleFix":"// before\n.initializationPolicy(new AllActiveInitPolicy()) // requires every db healthy\n// after\n.initializationPolicy(InitializationPolicy.FAILONLY) // init OK once any db is healthy","handlingStrategy":"validation","validationCode":"// Ensure at least the highest-weight endpoint is reachable before init\nEndpoint primary = config.getDatabases().get(0).getEndpoint();\ntry (Jedis p = new Jedis(primary.getHost(), primary.getPort())) {\n  p.auth(user, password); // throws early on bad credentials\n}","typeGuard":null,"tryCatchPattern":"try {\n  client = MultiDbClient.builder().multiDbConfig(cfg).build();\n} catch (JedisConnectionException e) {\n  // parse context from message; check which endpoint failed health check\n  throw new StartupAbortException(\"Redis fleet unhealthy at init\", e);\n}","preventionTips":["Keep health check timeouts generous enough for slow-starting Redis instances.","Confirm health-check credentials have ACL permissions to run the probe commands.","Monitor Redis availability before deployments so init doesn't race an outage.","Use a policy that needs only one healthy database if partial availability is acceptable."],"tags":["redis","jedis","connection","initialization","multi-db","health-check"],"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"}