mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
fix: skip polling loop when redis_cache is None
When Redis is not configured, the polling loop would sleep for the full lock_ttl (60s) with no chance of finding cached results. Add an early return to fall back to local health check immediately. Addresses Greptile review feedback on #26434.
This commit is contained in:
parent
c0d2f66033
commit
db0c297589
2 changed files with 40 additions and 0 deletions
|
|
@ -253,6 +253,15 @@ class SharedHealthCheckManager:
|
|||
# Always release the lock
|
||||
await self.release_health_check_lock()
|
||||
else:
|
||||
# If Redis is not configured, skip polling — there is no cache
|
||||
# to wait for.
|
||||
if self.redis_cache is None:
|
||||
return await perform_health_check(
|
||||
model_list=model_list,
|
||||
details=details,
|
||||
max_concurrency=max_concurrency,
|
||||
)
|
||||
|
||||
# Lock not acquired — poll for cached results until the lock
|
||||
# holder finishes or the lock expires, rather than falling back
|
||||
# to a redundant local health check after only 2 seconds.
|
||||
|
|
|
|||
|
|
@ -480,6 +480,37 @@ class TestSharedHealthCheckManager:
|
|||
assert healthy == [{"model": "cached-model"}]
|
||||
assert unhealthy == []
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_perform_shared_health_check_no_redis_skips_polling(self):
|
||||
"""Test that polling is skipped entirely when redis_cache is None"""
|
||||
manager = SharedHealthCheckManager(redis_cache=None)
|
||||
|
||||
model_list = [
|
||||
{"model_name": "test-model", "litellm_params": {"model": "test-model"}}
|
||||
]
|
||||
expected_healthy = [{"model": "test-model", "status": "healthy"}]
|
||||
expected_unhealthy = []
|
||||
|
||||
with (
|
||||
patch("asyncio.sleep") as mock_sleep,
|
||||
patch(
|
||||
"litellm.proxy.health_check_utils.shared_health_check_manager.perform_health_check"
|
||||
) as mock_perform,
|
||||
):
|
||||
mock_perform.return_value = (expected_healthy, expected_unhealthy, {})
|
||||
|
||||
healthy, unhealthy, _ = await manager.perform_shared_health_check(
|
||||
model_list, details=True
|
||||
)
|
||||
|
||||
# Should NOT sleep at all — falls back to local health check immediately
|
||||
mock_sleep.assert_not_called()
|
||||
mock_perform.assert_called_once_with(
|
||||
model_list=model_list, details=True, max_concurrency=None
|
||||
)
|
||||
assert healthy == expected_healthy
|
||||
assert unhealthy == expected_unhealthy
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_is_health_check_in_progress_true(
|
||||
self, shared_health_manager, mock_redis_cache
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue