redis/redis-py · error · TemporaryUnavailableException

No database connections currently available. This is a tempo

Error message

No database connections currently available. This is a temporary condition - please retry the operation.

What it means

Raised by `DefaultFailoverStrategyExecutor.execute()` (redis/asyncio/multidb/failover.py:118) as TemporaryUnavailableException when the underlying strategy raised NoValidDatabaseException (error 155) but the executor has not yet exhausted `failover_attempts`. It signals a transient condition: circuits are OPEN but may recover, so the caller should retry rather than abort. Once `failover_counter > failover_attempts`, the original NoValidDatabaseException propagates instead.

Source

Thrown at redis/asyncio/multidb/failover.py:118

    async def execute(self) -> AsyncDatabase:
        try:
            database = await self._strategy.database()
            self._reset()
            return database
        except NoValidDatabaseException as e:
            if self._next_attempt_ts == 0:
                self._next_attempt_ts = time.time() + self._failover_delay
                self._failover_counter += 1
            elif time.time() >= self._next_attempt_ts:
                self._next_attempt_ts += self._failover_delay
                self._failover_counter += 1

            if self._failover_counter > self._failover_attempts:
                self._reset()
                raise e
            else:
                raise TemporaryUnavailableException(
                    "No database connections currently available. "
                    "This is a temporary condition - please retry the operation."
                )

    def _reset(self) -> None:
        self._next_attempt_ts = 0
        self._failover_counter = 0

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Wrap command execution in a retry loop that catches `TemporaryUnavailableException` and retries with bounded backoff.
  2. Raise `failover_attempts` / shorten `failover_delay` in MultiDbConfig to give the client more chances before propagating.
  3. Ensure at least one backend recovers — investigate the upstream outage.
  4. Circuit-break at the application layer and shed load until the client stops raising this.

Example fix

# before
try:
    await client.set('k','v')
except TemporaryUnavailableException:
    raise  # propagates, caller sees a hard failure

# after
from redis.multidb.exception import TemporaryUnavailableException
import asyncio
for attempt in range(5):
    try:
        await client.set('k','v')
        break
    except TemporaryUnavailableException:
        await asyncio.sleep(1)
else:
    raise RuntimeError('redis still unavailable after retries')
Defensive patterns

Strategy: retry

Validate before calling

from redis.multidb.circuit import State as CBState

def likely_temporarily_unavailable(client) -> bool:
    # all circuits non-CLOSED -> next command may raise TemporaryUnavailableException
    return not any(db.circuit.state == CBState.CLOSED for db, _ in client.get_databases())

Type guard

from redis.multidb.exception import TemporaryUnavailableException

def is_temporary_unavailable(exc) -> bool:
    return isinstance(exc, TemporaryUnavailableException)

Try / catch

from redis.multidb.exception import TemporaryUnavailableException
import asyncio

for attempt in range(5):
    try:
        await client.set('k', 'v')
        break
    except TemporaryUnavailableException:
        await asyncio.sleep(backoff(attempt))
else:
    raise RuntimeError('redis unavailable after retries')

Prevention

When it happens

Trigger: Issuing any command through MultiDBClient during a window when every database circuit is OPEN and the failover retry budget (`failover_attempts`, default 10) has not been spent. Each attempt is spaced by `failover_delay` (default 12s).

Common situations: Brief full outage; all DBs cycling through OPEN→HALF_OPEN→recovery; client traffic hitting the client during the recovery window.

Related errors


AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04). Data as JSON: /data/errors/83ef0165fa1bed93.json. Report an issue: GitHub.