Skip to content

IPv6 Redis fallback cache URLs lose brackets and disable the cache #1227

Closed

Description

@Harsh23Kashyap

Version

7.87.0, also reproduced on current main (b182023e33bf3ef6bd9c388c80cd96eff936a9de).

Steps to Reproduce

Install the SDK and redis, then run:

from unittest.mock import patch

import redis
from posthog import Client
from posthog.utils import RedisFlagCache

for url in (
    "redis://127.0.0.1:6379/0?ttl=120",
    "rediss://cache.example.com:6380/1?ttl=120",
    "redis://[::1]:6379/0?ttl=120",
    "rediss://[2001:db8::1]:6380/1?ttl=120",
):
    # Keep redis-py's URL parsing real; skip only the network ping.
    with patch.object(redis.Redis, "ping", return_value=True):
        client = Client(
            "phc_test",
            send=False,
            thread=0,
            flag_fallback_cache_url=url,
        )
        try:
            print(url, isinstance(client.flag_cache, RedisFlagCache))
        finally:
            client.shutdown()

Expected Result

All four valid Redis URLs initialize a RedisFlagCache. IPv6 literals must remain bracketed in the URL passed to redis.from_url.

Actual Result

The IPv4 and hostname controls print True. Both bracketed IPv6 URLs print False, with warnings:

Port could not be cast to integer value as ':1:6379', flag caching disabled
Port could not be cast to integer value as 'db8::1:6380', flag caching disabled

Client._initialize_flag_cache reconstructs the Redis authority using parsed.hostname. urlparse removes the brackets from an IPv6 hostname, so redis://[::1]:6379/0 becomes redis://::1:6379/0. redis-py then rejects the port before any connection attempt, and the initializer returns None.

Reproduced twice with the full Client initializer. As a negative control, passing the original bracketed authority to redis.from_url parses both IPv6 hosts and ports correctly. Only ping was mocked; this does not claim a live Redis-server integration test.

This is separate from #1079/#1080: TLS scheme acceptance is already fixed, but the hostname reconstruction still breaks IPv6 for both redis and rediss.

Activity

  1. posthog commented on Nov 11, 2026

    @posthog
    Contributor

    PostHog self-driving picked up this issue. Status: Research is done.

    Somebody may already be working on it, so ask before you start a fix.

    Report (team access only): https://us.posthog.com/project/2/inbox/reports/01a1cadd-db40-74b1-abcc-00548f82696f?link_source=github_comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions