wsgi server: address family discovery is not quite right by jclulow · Pull Request #1006 · prometheus/client_python
By way of example, this is the output with and without the flags on an Ubuntu 22.04 system:
#!/usr/bin/env python3 import socket print("WITH type set:") print(socket.getaddrinfo("0.0.0.0", 9009, type=socket.SOCK_STREAM, flags=socket.AI_PASSIVE)) print("WITHOUT type set:") print(socket.getaddrinfo("0.0.0.0", 9009))
WITH type set:
[(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('0.0.0.0', 9009))]
WITHOUT type set:
[(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('0.0.0.0', 9009)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('0.0.0.0', 9009)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_RAW: 3>, 0, '', ('0.0.0.0', 9009))]
On some other platforms, getaddrinfo() requires at least the socket type to function as is expected here; e.g.,
WITH type set:
[(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 2>, 6, '', ('0.0.0.0', 9009))]
WITHOUT type set:
Traceback (most recent call last):
File "/tmp/sigh_test.py", line 10, in <module>
print(socket.getaddrinfo("0.0.0.0", 9009))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/socket.py", line 962, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno 9] service name not available for the specified socket type