Handle missing IPv6 support by the kernel

This is different from disabled IPv6.

Fixes #1050
This commit is contained in:
Unrud 2020-05-24 10:00:46 +02:00 committed by Unrud
parent 70a8d632fb
commit 6ec63ccc9b
2 changed files with 15 additions and 11 deletions

View File

@ -238,7 +238,9 @@ def serve(configuration, shutdown_socket):
# Address family not available (e.g. IPv6 disabled)
# macOS: IPv4 address for INET6 address family with
# IPV6_V6ONLY set
e.errno == errno.EADDRNOTAVAIL)):
e.errno == errno.EADDRNOTAVAIL or
# Address family not supported
e.errno == errno.EAFNOSUPPORT)):
continue
raise RuntimeError("Failed to start server %r: %s" % (
format_address(address), e)) from e

View File

@ -132,20 +132,22 @@ class TestBaseServerRequests(BaseTest):
socket.EAI_NONAME, server.COMPAT_EAI_ADDRFAMILY,
server.COMPAT_EAI_NODATA) or
str(exc_info.value) == "address family mismatched" or
exc_info.value.errno == errno.EADDRNOTAVAIL)
exc_info.value.errno == errno.EADDRNOTAVAIL or
exc_info.value.errno == errno.EAFNOSUPPORT)
def test_ipv6(self):
try:
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock:
# Only allow IPv6 connections to the IPv6 socket
sock.setsockopt(server.COMPAT_IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
try:
sock.setsockopt(
server.COMPAT_IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
# Find available port
sock.bind(("::1", 0))
self.sockname = sock.getsockname()[:2]
except OSError as e:
if e.errno == errno.EADDRNOTAVAIL:
if e.errno in (errno.EADDRNOTAVAIL, errno.EAFNOSUPPORT):
pytest.skip("IPv6 not supported")
raise
self.sockname = sock.getsockname()[:2]
self.configuration.update({
"server": {"hosts": "[%s]:%d" % self.sockname}}, "test")
self.thread.start()