Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions litellm/_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ def get_redis_connection_pool(

if redis_kwargs.pop("ssl", None):
redis_kwargs["connection_class"] = async_redis.SSLConnection
else:
redis_kwargs = {k: v for k, v in redis_kwargs.items() if not k.startswith("ssl_")}
Comment on lines +693 to +694

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 String false still selects TLS

When a direct caller or an environment-backed secret supplies ssl="false", the raw truthiness check selects SSLConnection instead of entering this filtering branch, causing plaintext Redis connections to attempt TLS and fail or time out. Normalize string boolean values before choosing the connection class so the non-TLS fix covers this supported configuration path.

Knowledge Base Used: Response Caching

return async_redis.BlockingConnectionPool(timeout=REDIS_CONNECTION_POOL_TIMEOUT, **redis_kwargs)


Expand Down
49 changes: 49 additions & 0 deletions tests/test_litellm/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,3 +737,52 @@ def test_connection_pool_env_redis_ssl_false_uses_plain_connection(monkeypatch):
assert pool is not None
assert pool.connection_class is async_redis.Connection
assert "ssl" not in pool.connection_kwargs


def test_connection_pool_drops_ssl_options_for_plain_connection(monkeypatch):
"""
ssl_* options must not reach a plain Connection.

The admin UI cache settings form always posts ssl_check_hostname, so a
non-TLS deployment ends up with ssl=False plus ssl_* kwargs; forwarding
those to redis.asyncio.Connection raises
"AbstractConnection.__init__() got an unexpected keyword argument
'ssl_check_hostname'" on every cache write.
"""
monkeypatch.delenv("REDIS_URL", raising=False)
monkeypatch.delenv("REDIS_SSL", raising=False)
monkeypatch.delenv("REDIS_CLUSTER_NODES", raising=False)

pool = get_redis_connection_pool(
host="plain-host",
port=6379,
ssl=False,
ssl_check_hostname=False,
ssl_cert_reqs="required",
ssl_ca_certs="/tmp/ca.pem",
)

assert pool is not None
assert pool.connection_class is async_redis.Connection
assert not [k for k in pool.connection_kwargs if k.startswith("ssl")]
assert pool.connection_class(**pool.connection_kwargs) is not None


def test_connection_pool_keeps_ssl_options_for_tls_connection(monkeypatch):
"""ssl=True must keep the ssl_* options that SSLConnection understands."""
monkeypatch.delenv("REDIS_URL", raising=False)
monkeypatch.delenv("REDIS_SSL", raising=False)
monkeypatch.delenv("REDIS_CLUSTER_NODES", raising=False)

pool = get_redis_connection_pool(
host="tls-host",
port=6380,
ssl=True,
ssl_check_hostname=True,
ssl_cert_reqs="required",
)

assert pool is not None
assert pool.connection_class is async_redis.SSLConnection
assert pool.connection_kwargs["ssl_check_hostname"] is True
assert pool.connection_kwargs["ssl_cert_reqs"] == "required"
Loading