fix(caching): guard against None async_redis_conn_pool in RedisCache.disconnect - #31211
fix(caching): guard against None async_redis_conn_pool in RedisCache.disconnect#31211adhavan18 wants to merge 2 commits into
Conversation
Greptile SummaryGuards against a
Confidence Score: 4/5Safe to merge — the change is a minimal, well-scoped guard with no behavioural impact on non-cluster configurations. The one-line guard correctly handles the cluster-mode shutdown crash without touching any other code path. The only gap is the absence of a regression test, so a future refactor of disconnect() could reintroduce the same bug silently. No files require special attention beyond the noted lack of a test for the cluster-mode disconnect path.
|
| Filename | Overview |
|---|---|
| litellm/caching/redis_cache.py | Adds a None guard around async_redis_conn_pool.disconnect() to prevent AttributeError during shutdown in Redis cluster mode; the fix is correct and minimal with no new tests added. |
Comments Outside Diff (1)
-
litellm/caching/redis_cache.py, line 1277-1283 (link)No regression test for the cluster-mode disconnect path
The PR fixes a real crash but adds no test to prevent it from regressing. A unit test for
disconnect()whenasync_redis_conn_pool is Nonewould be straightforward — mock the Redis client'sclose()and assert noAttributeErroris raised — and would fit naturally alongside the existing mocked tests intests/test_litellm/caching/test_redis_connection_pool.py.Rule Used: What: Ensure that any PR claiming to fix an issue ... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Reviews (1): Last reviewed commit: "fix(caching): guard against None async_r..." | Re-trigger Greptile
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Retargeted base branch from |
0f02d23 to
d0fa53f
Compare
|
Rebased onto the current |
|
Thanks for this fix, @adhavan18 — the root cause explanation for the cluster-mode shutdown crash is clear and the one-line guard is exactly the right minimal fix. Triggering a fresh Greptile review since the PR was rebased onto |
|
@Sameerlite — following up on the open items: CI failure ( Investigated the failure: the The fix itself is unchanged and still applies cleanly to the current upstream: one |
|
CI status update: the |
|
Thanks @Sameerlite! Regarding the test request — I ran the existing unit tests locally, all pass. Re: Re: adding a unit test — Would be happy to add a |
|
Regression tests added per reviewer request Added two tests to
Both tests pass locally. Pushing shortly. |
|
Thanks @Sameerlite! Both points addressed: disconnect() test — this is already in the PR. misc / Run tests — not related to this change. The failing test is |
|
@Sameerlite gentle follow-up — both of your asks are addressed above (the |
…disconnect Fixes BerriAI#31206 When REDIS_CLUSTER_NODES is set, get_redis_connection_pool() returns None because the cluster mode path exits early. This causes RedisCache.__init__ to store self.async_redis_conn_pool = None. At shutdown, disconnect() then crashes with AttributeError: 'NoneType' has no attribute 'disconnect'. Add a None guard before calling .disconnect() on the connection pool.
…_conn_pool is None
cc745cf to
fd02352
Compare
|
@Sameerlite re-checked this against async def disconnect(self):
await self.async_redis_conn_pool.disconnect(inuse_connections=True)
try:
self.redis_client.close()
except Exception as e:
verbose_logger.debug("Error closing sync Redis client: %s", e)
Both of your asks are in the PR: Low priority from my side, just noting it is a one-line guard on a shutdown crash. |
|
still relevant, and happy to rebase if it's gone stale. one thing that might be holding this up mechanically rather than editorially: only 3 checks have ever run here (PR title, CodeRabbit, Veria). the full CI suite has never run on this PR, since fork PRs need a maintainer to approve the workflow run. so there's no green signal to review against, through no fault of the diff. could someone approve the workflow run? for contrast, #31319 did get approved and came back 46/50 green, with the 4 reds in checks unrelated to that diff. happy to fix anything the run surfaces here. |
|
recheck |
1 similar comment
|
recheck |
Fixes #31206
Problem
When
REDIS_CLUSTER_NODESis set,get_redis_connection_pool()returnsNonebecause the cluster-mode path exits early:This causes
RedisCache.__init__to storeself.async_redis_conn_pool = None. At shutdown,proxy_shutdown_eventcallsawait litellm.cache.disconnect()which callsRedisCache.disconnect(), which then crashes:Fix
Add a
Noneguard before calling.disconnect()on the connection pool. The synchronousself.redis_client.close()is still attempted (it is already inside a try/except) so cluster-mode clients are still cleaned up gracefully on shutdown.Verification
The crash is reproducible by setting
REDIS_CLUSTER_NODESand stopping LiteLLM (rolling update or graceful shutdown). After this fix, shutdown completes without theAttributeError.