From: Ben Darnell Date: Sat, 22 Jun 2019 16:45:57 +0000 (-0400) Subject: netutil: Ignore EADDRNOTAVAIL when binding to localhost ipv6 X-Git-Tag: v6.1.0b1~67^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=090e6cca9efb90a502e57688b038ec0351947d11;p=thirdparty%2Ftornado.git netutil: Ignore EADDRNOTAVAIL when binding to localhost ipv6 This happens in docker with default configurations and is generally harmless. Fixes #2274 --- diff --git a/tornado/netutil.py b/tornado/netutil.py index 293f3aab5..b309d67d1 100644 --- a/tornado/netutil.py +++ b/tornado/netutil.py @@ -159,7 +159,29 @@ def bind_sockets( sockaddr = tuple([host, bound_port] + list(sockaddr[2:])) sock.setblocking(False) - sock.bind(sockaddr) + try: + sock.bind(sockaddr) + except OSError as e: + if ( + errno_from_exception(e) == errno.EADDRNOTAVAIL + and address == "localhost" + and sockaddr[0] == "::1" + ): + # On some systems (most notably docker with default + # configurations), ipv6 is partially disabled: + # socket.has_ipv6 is true, we can create AF_INET6 + # sockets, and getaddrinfo("localhost", ..., + # AF_PASSIVE) resolves to ::1, but we get an error + # when binding. + # + # Swallow the error, but only for this specific case. + # If EADDRNOTAVAIL occurs in other situations, it + # might be a real problem like a typo in a + # configuration. + sock.close() + continue + else: + raise bound_port = sock.getsockname()[1] sock.listen(backlog) sockets.append(sock)