From 2477d310e8f8b932d54749def65731abf3c72151 Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Thu, 8 Mar 2018 16:36:00 -0500 Subject: [PATCH] Fix [Errno -9] Address family for hostname not supported On some cloud providers (OVH) when using an ipv4 address with socket.AF_INET6 address family, we see the following exception when trying to bind to the fingergw.listen_address: socket.gaierror: [Errno -9] Address family for hostname not supported Work around this by using socket.getaddrinfo() to first look up the supported socket family, then use that value to setup the socketserver address_family. Change-Id: I31df8f2fa8f1b986a2c4190008f13fe155991f2c Signed-off-by: Paul Belanger --- zuul/lib/streamer_utils.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/zuul/lib/streamer_utils.py b/zuul/lib/streamer_utils.py index 3d2d561b9b..e28ad11b11 100644 --- a/zuul/lib/streamer_utils.py +++ b/zuul/lib/streamer_utils.py @@ -71,9 +71,27 @@ class CustomThreadingTCPServer(socketserver.ThreadingTCPServer): Custom version that allows us to drop privileges after port binding. ''' - address_family = socket.AF_INET6 - def __init__(self, *args, **kwargs): + # NOTE(pabelanger): Set up address_family for socketserver based on the + # fingergw.listen_address setting in zuul.conf. + # param tuple args[0]: The address and port to bind to for + # socketserver. + server_address = args[0] + address_family = None + for res in socket.getaddrinfo( + server_address[0], server_address[1], 0, self.socket_type): + if res[0] == socket.AF_INET6: + # If we get an IPv6 address, break our loop and use that first. + address_family = res[0] + break + elif res[0] == socket.AF_INET: + address_family = res[0] + + # Check to see if getaddrinfo failed. + if not address_family: + raise Exception("getaddrinfo returns an empty list") + + self.address_family = address_family self.user = kwargs.pop('user', None) self.pid_file = kwargs.pop('pid_file', None) socketserver.ThreadingTCPServer.__init__(self, *args, **kwargs)