Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

IPv6 seems unsupported for metrics-listener #6644

Open
cherti opened this issue Jan 6, 2020 · 4 comments
Open

IPv6 seems unsupported for metrics-listener #6644

cherti opened this issue Jan 6, 2020 · 4 comments
Labels
A-Metrics metrics, measures, stuff we put in Prometheus P4 (OBSOLETE: use S- labels.) Okay backlog: will not schedule, will accept patches S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.

Comments

@cherti
Copy link

cherti commented Jan 6, 2020

Description

metrics-listener makes synapse crash when assigned an IPv6-bind_address

Steps to reproduce

Add

listeners:
  - type: metrics
    port: 19000
    bind_addresses:
      - '127.0.0.1'

to the /etc/matrix-synapse/homeserver.yaml and everything works, change it to either

listeners:
  - type: metrics
    port: 19000
    bind_addresses:
      - '::1'

or

listeners:
  - type: metrics
    port: 19000
    bind_addresses:
      - '127.0.0.1'
      - '::1'

and synapse will not start anymore, instead yielding the following traceback:

twisted: [] Traceback (most recent call last):
twisted: []   File "/usr/lib/python3/dist-packages/synapse/app/_base.py", line 271, in start
twisted: []     hs.start_listening(listeners)
twisted: []   File "/usr/lib/python3/dist-packages/synapse/app/homeserver.py", line 293, in start_listening
twisted: []     _base.listen_metrics(listener["bind_addresses"], listener["port"])
twisted: []   File "/usr/lib/python3/dist-packages/synapse/app/_base.py", line 160, in listen_metrics
twisted: []     start_http_server(port, addr=host, registry=RegistryProxy)
twisted: []   File "/usr/lib/python3/dist-packages/synapse/metrics/_exposition.py", line 242, in start_http_server
twisted: []     httpd = _ThreadingSimpleServer((addr, port), CustomMetricsHandler)
twisted: []   File "/usr/lib/python3.7/socketserver.py", line 452, in __init__
twisted: []     self.server_bind()
twisted: []   File "/usr/lib/python3.7/http/server.py", line 137, in server_bind
twisted: []     socketserver.TCPServer.server_bind(self)
twisted: []   File "/usr/lib/python3.7/socketserver.py", line 466, in server_bind
twisted: []     self.socket.bind(self.server_address)
twisted: [] socket.gaierror: [Errno -9] Address family for hostname not supported
twisted: [] Unhandled error in Deferred:
twisted: [] 
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/synapse/app/_base.py", line 271, in start
    hs.start_listening(listeners)
  File "/usr/lib/python3/dist-packages/synapse/app/homeserver.py", line 293, in start_listening
    _base.listen_metrics(listener["bind_addresses"], listener["port"])
  File "/usr/lib/python3/dist-packages/synapse/app/_base.py", line 160, in listen_metrics
    start_http_server(port, addr=host, registry=RegistryProxy)
  File "/usr/lib/python3/dist-packages/synapse/metrics/_exposition.py", line 242, in start_http_server
    httpd = _ThreadingSimpleServer((addr, port), CustomMetricsHandler)
  File "/usr/lib/python3.7/socketserver.py", line 452, in __init__
    self.server_bind()
  File "/usr/lib/python3.7/http/server.py", line 137, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/lib/python3.7/socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
socket.gaierror: [Errno -9] Address family for hostname not supported

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
    result = g.send(result)
  File "/usr/lib/python3/dist-packages/synapse/app/homeserver.py", line 413, in start
    _base.start(hs, config.listeners)
  File "/usr/lib/python3/dist-packages/synapse/app/_base.py", line 281, in start
    sys.exit(1)
SystemExit: 1

Version information

@richvdh
Copy link
Member

richvdh commented Jan 6, 2020

this is mostly because of python's HTTPServer's patchy support of IPv6 addresses: see https://bugs.python.org/issue24209

@neilisfragile neilisfragile added z-bug (Deprecated Label) z-p2 (Deprecated Label) labels Jan 14, 2020
@AluisioASG
Copy link

Applying the workaround at python/cpython#11767 to start_http_server enables using IPv6 literals as bind addresses. I haven't checked how that impacts IPv4 or hostnames.

@MadLittleMods MadLittleMods added the A-Metrics metrics, measures, stuff we put in Prometheus label Nov 10, 2021
@DMRobertson DMRobertson added S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. P4 (OBSOLETE: use S- labels.) Okay backlog: will not schedule, will accept patches and removed z-bug (Deprecated Label) z-p2 (Deprecated Label) labels Nov 18, 2021
@DMRobertson
Copy link
Contributor

Applying the workaround at python/cpython#11767 to start_http_server enables using IPv6 literals as bind addresses. I haven't checked how that impacts IPv4 or hostnames.

Worth noting that the corresponding Python bug was marked as resolved in 3.8. Maybe this has been solved for anyone running that version or newer?

@bbusse
Copy link

bbusse commented Dec 28, 2021

This is still an issue with Python 3.8.12 and synapse fcfe675
As a workaround, explicitly setting AF_INET6 in Python's socket.py, line 231: _socket.socket.init(self, AF_INET6, type, proto, fileno) works

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Metrics metrics, measures, stuff we put in Prometheus P4 (OBSOLETE: use S- labels.) Okay backlog: will not schedule, will accept patches S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Projects
None yet
Development

No branches or pull requests

7 participants