redis/redis-py · critical · NoValidDatabaseException
Initial connection failed - no active database found
Error message
Initial connection failed - no active database found
What it means
Raised by MultiDBClient.initialize() (redis/asyncio/multidb/client.py:140) after the initial health check completes but no database has a CLOSED circuit breaker. The client iterates `self._databases` looking for the first CLOSED database to promote as active; if every database is OPEN (unhealthy), it cannot establish an active connection and aborts startup with NoValidDatabaseException.
Source
Thrown at redis/asyncio/multidb/client.py:140
self._check_databases_health,
)
)
is_active_db_found = False
for database, weight in self._databases:
# Set on state changed callback for each circuit.
database.circuit.on_state_changed(self._on_circuit_state_change_callback)
# Set states according to a weights and circuit state
if database.circuit.state == CBState.CLOSED and not is_active_db_found:
# Directly set the active database during initialization
# without recording a geo failover metric
self.command_executor._active_database = database
is_active_db_found = True
if not is_active_db_found:
raise NoValidDatabaseException(
"Initial connection failed - no active database found"
)
self.initialized = True
def get_databases(self) -> Databases:
"""
Returns a sorted (by weight) list of all databases.
"""
return self._databases
async def set_active_database(self, database: AsyncDatabase) -> None:
"""
Promote one of the existing databases to become an active.
"""
exists = None
for existing_db, _ in self._databases:View on GitHub (pinned to da03cdc7e8)
Solutions
- Verify each `DatabaseConfig` URL/credentials with a direct `redis-py` PING before constructing MultiDBClient.
- Bring up at least one Redis instance the client can reach (e.g. `invoke devenv`).
- Check network/TLS: ensure host/port reachable, certificates valid, firewall rules allow egress.
- If some DBs are expected to be down at startup, confirm `initial_health_check_policy` is set to `ONE_AVAILABLE` or `MAJORITY_AVAILABLE` in `MultiDbConfig`.
Example fix
# before
client = MultiDBClient(MultiDbConfig(databases_config=[
DatabaseConfig(from_url='redis://wrong-host:6379/0'),
]))
await client.initialize() # NoValidDatabaseException
# after
# verify endpoint first
import redis.asyncio as redis
r = redis.from_url('redis://correct-host:6379/0')
await r.ping()
client = MultiDBClient(MultiDbConfig(databases_config=[
DatabaseConfig(from_url='redis://correct-host:6379/0'),
]))
await client.initialize() Defensive patterns
Strategy: validation
Validate before calling
import redis.asyncio as redis
async def all_endpoints_reachable(urls: list[str]) -> bool:
for u in urls:
r = redis.from_url(u)
try:
await r.ping()
except Exception:
await r.aclose()
return False
finally:
await r.aclose()
return True
# call before MultiDBClient(...).initialize() Type guard
from redis.asyncio.multidb.client import MultiDBClient
def is_multidb(obj) -> bool:
return isinstance(obj, MultiDBClient) Try / catch
from redis.multidb.exception import NoValidDatabaseException
try:
await client.initialize()
except NoValidDatabaseException:
# startup cannot proceed: log, alert, abort or fall back to single-client mode
raise Prevention
- Pre-flight PING every configured endpoint with a plain redis-py client before constructing MultiDBClient.
- Stand up the docker-compose (`invoke devenv`) or equivalent infra before running tests/services.
- Treat initialize() as a hard startup gate in process orchestration (systemd/k8s readiness probe).
When it happens
Trigger: Constructing a `MultiDBClient` and calling `await client.initialize()` (or issuing the first command which auto-initializes) when all configured databases are unreachable, misconfigured, or failed their initial health checks. Also reached if the initial health check policy is lenient (ONE_AVAILABLE) but even one healthy DB could not be found.
Common situations: All Redis endpoints down or wrong host/port in `DatabaseConfig`; network partition isolating the client from every DB; TLS/auth misconfiguration causing every PING probe to fail; Redis Enterprise cluster not yet bootstrapped; CI running without the docker-compose stack up.
Related errors
- Cannot set active database, database is unhealthy
- Initial health check failed. Initial health check policy: {s
- No valid database available for communication
- No database connections currently available. This is a tempo
- Unhealthy database
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/0d1569121f845421.json.
Report an issue: GitHub.