{"id":"eaeb78b65952bc96","repo":"redis/redis-py","slug":"no-connection-available-eaeb78","errorCode":null,"errorMessage":"No connection available.","messagePattern":"No connection available\\.","errorType":"exception","errorClass":"ConnectionError","httpStatus":null,"severity":"error","filePath":"redis/connection.py","lineNumber":3699,"sourceCode":"        \"\"\"\n        start_time_acquired = time.monotonic()\n        # Make sure we haven't changed process.\n        self._checkpid()\n        is_created = False\n\n        # Try and get a connection from the pool. If one isn't available within\n        # self.timeout then raise a ``ConnectionError``.\n        connection = None\n        try:\n            if self._in_maintenance:\n                self._lock.acquire()\n                self._locked = True\n            try:\n                connection = self.pool.get(block=True, timeout=self.timeout)\n            except Empty:\n                # Note that this is not caught by the redis client and will be\n                # raised unless handled by application code. If you want never to\n                raise ConnectionError(\"No connection available.\")\n\n            # If the ``connection`` is actually ``None`` then that's a cue to make\n            # a new connection to add to the pool.\n            if connection is None:\n                # Start timing for observability\n                start_time_created = time.monotonic()\n                connection = self.make_connection()\n                is_created = True\n        finally:\n            if self._locked:\n                try:\n                    self._lock.release()\n                except Exception:\n                    pass\n                self._locked = False\n\n        # Record state transition: IDLE -> USED\n        # (make_connection already recorded IDLE +1 for new connections)","sourceCodeStart":3681,"sourceCodeEnd":3717,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/connection.py#L3681-L3717","documentation":"Raised as a ConnectionError by BlockingConnectionPool.get_connection (connection.py:3690-3699) when the internal queue.get(block=True, timeout=self.timeout) raises Empty — i.e. no connection became available within the configured timeout (default 20s). Unlike the non-blocking pool's immediate MaxConnectionsError, BlockingConnectionPool waits, and this error means the wait elapsed with nothing freed.","triggerScenarios":"Using BlockingConnectionPool and exhausting all connections for longer than `timeout` seconds: every connection is checked out (e.g. stuck in slow/blocking commands or leaked) and none is returned before the deadline.","commonSituations":"Long-running blocking commands (BLPOP, WAIT, MONITOR) holding connections; connection leaks; timeout set too low for realistic operation latency; a stall/deadlock where threads hold connections and block waiting for connections held by other threads.","solutions":["Increase the BlockingConnectionPool timeout (timeout=60) or set timeout=None to block indefinitely if you prefer waiting over failing.","Raise max_connections to match peak concurrency.","Fix connection leaks and avoid holding connections across long blocking commands.","Catch ConnectionError around get_connection/pipeline and apply a retry/backoff for transient exhaustion."],"exampleFix":"# before\npool = redis.BlockingConnectionPool(max_connections=10, timeout=2)\n# raises ConnectionError: No connection available. under load\n\n# after\npool = redis.BlockingConnectionPool(max_connections=50, timeout=30)\n# or block forever\npool = redis.BlockingConnectionPool(max_connections=50, timeout=None)","handlingStrategy":"retry","validationCode":"def blocking_pool(peak_concurrency: int, wait_s: float = 30.0) -> redis.BlockingConnectionPool:\n    return redis.BlockingConnectionPool(\n        max_connections=max(peak_concurrency, 50), timeout=wait_s)\n\nclient = redis.Redis(connection_pool=blocking_pool(my_thread_count))","typeGuard":null,"tryCatchPattern":"from redis.exceptions import ConnectionError\nfor _ in range(3):\n    try:\n        return client.get(\"k\")\n    except ConnectionError as e:\n        if \"No connection available\" in str(e):\n            time.sleep(0.5)\n            continue\n        raise\nraise","preventionTips":["Size max_connections and timeout to realistic peak load and latency.","Avoid long blocking commands tying up pooled connections; use a dedicated connection for them.","Fix connection leaks so connections are returned promptly.","Consider timeout=None if blocking is preferable to failing."],"tags":["connection-pool","resource-limits","configuration","timeout"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}