Skip to content

Commit e1711f2

Browse files
committed
wsgi server: allow binding to ipv6 address
Reproduce the fix in python3.8 http.server by doing a dns lookup and using the correct address family Fixes #567 Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
1 parent 9118c02 commit e1711f2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

prometheus_client/exposition.py

+11
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,20 @@ class ThreadingWSGIServer(ThreadingMixIn, WSGIServer):
143143
daemon_threads = True
144144

145145

146+
def _get_best_family(*address):
147+
infos = socket.getaddrinfo(
148+
*address,
149+
type=socket.SOCK_STREAM,
150+
flags=socket.AI_PASSIVE,
151+
)
152+
family, type, proto, canonname, sockaddr = next(iter(infos))
153+
return family, sockaddr[0]
154+
155+
146156
def start_wsgi_server(port, addr='', registry=REGISTRY):
147157
"""Starts a WSGI server for prometheus metrics as a daemon thread."""
148158
app = make_wsgi_app(registry)
159+
ThreadingWSGIServer.address_family, addr = _get_best_family(addr, port)
149160
httpd = make_server(addr, port, app, ThreadingWSGIServer, handler_class=_SilentHandler)
150161
t = threading.Thread(target=httpd.serve_forever)
151162
t.daemon = True

0 commit comments

Comments
 (0)