Skip to content

Commit

Permalink
Fix IPv6 address case in server_list function (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anvil authored Feb 9, 2021
1 parent 5e799c2 commit 05c0ff9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion faust/transport/drivers/aiokafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,24 @@
""".strip()


def __canon_host(host, default):
"""Ensure host is correctly formatted for aiokafka. That means IPv6
addresses must enclosed in squared brackets.
"""
if not host:
return default
if ":" in host:
return f"[{host}]"
return host


def server_list(urls: List[URL], default_port: int) -> List[str]:
"""Convert list of urls to list of servers accepted by :pypi:`aiokafka`."""
default_host = "127.0.0.1"
return [f"{u.host or default_host}:{u.port or default_port}" for u in urls]
# Yarl strips [] from IPv6 adresses, and aiokafka expects them.
return [
f"{__canon_host(u.host, default_host)}:{u.port or default_port}" for u in urls
]


class ConsumerRebalanceListener(aiokafka.abc.ConsumerRebalanceListener): # type: ignore
Expand Down

0 comments on commit 05c0ff9

Please sign in to comment.