{"id":"654de1f0e10e3b3f","repo":"redis/redis-py","slug":"no-connection-available","errorCode":null,"errorMessage":"No connection available.","messagePattern":"No connection available\\.","errorType":"exception","errorClass":"ConnectionError","httpStatus":null,"severity":"error","filePath":"redis/asyncio/connection.py","lineNumber":3100,"sourceCode":"        start_time_acquired = time.monotonic()\n\n        try:\n            async with self._condition:\n                async with async_timeout(self.timeout):\n                    await self._condition.wait_for(self.can_get_connection)\n                    async with self._maybe_pool_lock():\n                        # Track connection count before to detect if a new connection is created\n                        connections_before = len(self._available_connections) + len(\n                            self._in_use_connections\n                        )\n                        start_time_created = time.monotonic()\n                        connection = super().get_available_connection()\n                        connections_after = len(self._available_connections) + len(\n                            self._in_use_connections\n                        )\n                        is_created = connections_after > connections_before\n        except asyncio.TimeoutError as err:\n            raise ConnectionError(\"No connection available.\") from err\n\n        # We now perform the connection check outside of the lock.\n        try:\n            await self.ensure_connection(connection)\n\n            if is_created:\n                await record_connection_create_time(\n                    connection_pool=self,\n                    duration_seconds=time.monotonic() - start_time_created,\n                )\n\n            await record_connection_wait_time(\n                pool_name=get_pool_name(self),\n                duration_seconds=time.monotonic() - start_time_acquired,\n            )\n\n            return connection\n        except BaseException:","sourceCodeStart":3082,"sourceCodeEnd":3118,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/asyncio/connection.py#L3082-L3118","documentation":"Raised as ConnectionError by BlockingConnectionPool.get_connection() when the configured timeout elapses while waiting for a connection to become available. Unlike the non-blocking pool (which raises MaxConnectionsError immediately), BlockingConnectionPool waits on a condition variable; if no connection is released within self.timeout, asyncio.TimeoutError is caught and re-raised as 'No connection available.'","triggerScenarios":"Using BlockingConnectionPool with a finite timeout and exhausting all connections for longer than timeout. Fires at connection.py:3099-3100. The caller's command waits, then fails instead of hanging forever.","commonSituations":"Undersized max_connections combined with long-running or leaked commands; a slow/stalled Redis backing up every connection; blocking operations (BLPOP, long EVAL) tying up connections; timeout set too low for the workload.","solutions":["Increase max_connections on the BlockingConnectionPool.","Increase the pool timeout to tolerate transient stalls.","Find and fix long-running or leaked commands holding connections.","Move long-blocking commands (BLPOP, long Lua) to a dedicated client/pool."],"exampleFix":"// before\npool = BlockingConnectionPool(max_connections=10, timeout=1)\n// after\npool = BlockingConnectionPool(max_connections=50, timeout=10)","handlingStrategy":"retry","validationCode":"def tune_blocking_pool(max_concurrent_tasks, per_task_ms):\n    timeout = max(5, per_task_ms / 1000 * max_concurrent_tasks / 100)\n    return dict(max_connections=max_concurrent_tasks, timeout=timeout)\n\npool = BlockingConnectionPool(**tune_blocking_pool(N, D))","typeGuard":"def will_likely_block(pool, inflight) -> bool:\n    return inflight >= pool.max_connections and pool.timeout is not None","tryCatchPattern":"from redis.exceptions import ConnectionError\ntry:\n    await redis.get('k')\nexcept ConnectionError as e:\n    if 'No connection available' in str(e):\n        await asyncio.sleep(backoff)\n        await redis.get('k')","preventionTips":["Size max_connections to peak concurrency.","Keep long-blocking commands on a separate pool.","Tune timeout to your tolerance; bound fan-out with a Semaphore.","Investigate leaked or slow commands."],"tags":["pool","blocking-pool","timeout","concurrency","asyncio"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}