Skip to content

Commit

Permalink
Fix for aio-libs#5156
Browse files Browse the repository at this point in the history
  • Loading branch information
derlih committed Oct 29, 2020
1 parent a2dad92 commit 48de143
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions aiohttp/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from .abc import AbstractResolver
from .helpers import get_running_loop
from .log import internal_logger

__all__ = ("ThreadedResolver", "AsyncResolver", "DefaultResolver")

Expand Down Expand Up @@ -32,15 +33,21 @@ async def resolve(
)

hosts = []
for family, _, proto, _, address in infos:
if family == socket.AF_INET6 and address[3]: # type: ignore
# This is essential for link-local IPv6 addresses.
# LL IPv6 is a VERY rare case. Strictly speaking, we should use
# getnameinfo() unconditionally, but performance makes sense.
host, _port = socket.getnameinfo(
address, socket.NI_NUMERICHOST | socket.NI_NUMERICSERV
)
port = int(_port)
for info in infos:
family, _, proto, _, address = info
if family == socket.AF_INET6:
# https://github.com/aio-libs/aiohttp/issues/5156
if len(address) != 4:
internal_logger.warning(f"Bad address format in {info}")
continue
if address[3]: # type: ignore
# This is essential for link-local IPv6 addresses.
# LL IPv6 is a VERY rare case. Strictly speaking, we should use
# getnameinfo() unconditionally, but performance makes sense.
host, _port = socket.getnameinfo(
address, socket.NI_NUMERICHOST | socket.NI_NUMERICSERV
)
port = int(_port)
else:
host, port = address[:2]
hosts.append(
Expand Down

0 comments on commit 48de143

Please sign in to comment.