redis/jedis · error · JedisException

Database can not be removed due to no healthy database…

Error message

Database can not be removed due to no healthy database available to switch!

What it means

When removing an endpoint that is currently the active database, the provider attempts to fail over by setting a healthy candidate as active. If no healthy alternative database exists, a JedisException is thrown because removal would leave the client without an active database.

Solutions

  1. Restore health of at least one other database (fix connectivity, credentials) before removing the active endpoint.
  2. Remove a non-active endpoint instead, or first switch the active database manually to a healthy one.
  3. Verify health-check configuration (timeouts, thresholds) isn't marking healthy databases as unhealthy.
  4. Catch JedisException and defer the removal until failover is possible.

Example fix

// before
provider.remove(activeEndpoint); // fails if no healthy alternative

// after
// wait for or ensure another database is healthy
if (isAnyOtherHealthy(activeEndpoint)) {
  provider.remove(activeEndpoint);
} else {
  log.warn("Defer removal: no healthy database to switch to");
}
Defensive patterns

Strategy: fallback

Validate before calling

// confirm another healthy database exists before removing the active one
boolean otherHealthy = databases.stream()
    .filter(db -> !db.getEndpoint().equals(activeEndpoint))
    .anyMatch(db -> healthCheck(db.getEndpoint()) == HealthStatus.HEALTHY);

Try / catch

try {
  provider.remove(activeEndpoint);
} catch (JedisException e) {
  if (e.getMessage().contains("no healthy database")) {
    // defer removal; restore health of another database first
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Calling provider.remove(endpoint) where the endpoint being removed is the active database and every other registered database fails its health check (or none exist as healthy candidates).

Common situations: Draining a primary during a regional outage when secondaries are also unhealthy; removing the only healthy database while others are down; health checks failing due to network issues making all remaining databases look dead.

Related errors


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/eb013f8eb2e9134f. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/mcf/MultiDbConnectionProvider.java:292

    Map.Entry<Endpoint, Database> notificationData = null;
    activeDatabaseChangeLock.lock();
    try {
      Database databaseToRemove = databaseMap.get(endpoint);
      boolean isActiveDatabase = (activeDatabase == databaseToRemove);

      if (isActiveDatabase) {
        log.info("Active database is being removed. Finding a new active database...");
        Map.Entry<Endpoint, Database> candidate = findWeightedHealthyDatabaseToIterate(
          databaseToRemove);
        if (candidate != null) {
          Database selectedDatabase = candidate.getValue();
          if (setActiveDatabase(selectedDatabase, true)) {
            log.info("New active database set to {}", candidate.getKey());
            notificationData = candidate;
          }
        } else {
          throw new JedisException(
              "Database can not be removed due to no healthy database available to switch!");
        }
      }

      // Remove from health status manager first
      healthStatusManager.unregisterListener(endpoint, this::onHealthStatusChange);
      healthStatusManager.remove(endpoint);

      // Remove from database map
      databaseMap.remove(endpoint);

      // Close the database resources
      if (databaseToRemove != null) {
        databaseToRemove.setDisabled(true);
        databaseToRemove.close();
      }
    } finally {
      activeDatabaseChangeLock.unlock();

View on GitHub (pinned to 6dac31d4c2)