Skip to content

Commit

Permalink
wsgi server: address family discovery is not quite right (#1006)
Browse files Browse the repository at this point in the history
The code introduced to improve binding to an IPv6 address is based on
similar code in Python itself, but is missing some critical arguments to
the socket.getaddrinfo() call: in particular, the socket type must be
set to SOCK_STREAM, because we want a TCP connection; the AI_PASSIVE
flag should also be passed because we intend to use the result for
binding a listen socket rather than making an outbound connection.

Signed-off-by: Joshua M. Clulow <[email protected]>
  • Loading branch information
jclulow authored Feb 13, 2024
1 parent 1f8ceb7 commit 6ae7737
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion prometheus_client/exposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _get_best_family(address, port):
# binding an ipv6 address is requested.
# This function is based on what upstream python did for http.server
# in https://github.com/python/cpython/pull/11767
infos = socket.getaddrinfo(address, port)
infos = socket.getaddrinfo(address, port, type=socket.SOCK_STREAM, flags=socket.AI_PASSIVE)
family, _, _, _, sockaddr = next(iter(infos))
return family, sockaddr[0]

Expand Down

0 comments on commit 6ae7737

Please sign in to comment.