element-hq / synapse

Synapse: Matrix homeserver written in Python/Twisted.
https://element-hq.github.io/synapse
GNU Affero General Public License v3.0
1.52k stars 186 forks source link

Twisted has a new version which causes failure #17882

Open phreed opened 1 week ago

phreed commented 1 week ago

Description

I just started getting this error.

This is due to an update to Twisted from v24.7.0 to v24.10.0 . Forcing the older version pip install --force-reinstall -v "Twisted==24.7.0" and that corrected the error. Apparently, _canonicalHeaderName = Headers()._encodeName is no longer valid.

Steps to reproduce

mkdir ~/synapse
python3.12 -m venv ~/synapse/env
source ~/synapse/env/bin/activate

pip install --upgrade pip
pip install --upgrade setuptools
pip install matrix-synapse
cd  ~/synapse
python -m synapse.app.homeserver --server-name matrix.mcp.mil --config-path homeserver.yaml --generate-config

Homeserver

generating a new homeserver.yaml

Synapse Version

1.117.0

Installation Method

pip (from PyPI)

Database

sqlite

Workers

Single process

Platform

Ubuntu 24 fedora 40

Configuration

No response

Relevant log output

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
 ...
    from synapse.http.site import SynapseRequest
  File "/var/home/me/synapse/env/lib64/python3.12/site-packages/synapse/http/site.py", line 39, in <module>
    from synapse.http.proxy import ProxySite
  File "/var/home/me/synapse/env/lib64/python3.12/site-packages/synapse/http/proxy.py", line 72, in <module>
    _canonicalHeaderName = Headers()._encodeName
                           ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Headers' object has no attribute '_encodeName'

Anything else that would be useful to know?

I updated the synapse/http/proxy.py about line 74 to gain some insight. While this is not a fix, it may be useful.

 if hasattr(Headers, "_canonicalNameCaps"):
    logger.warning(f'you appear to be running an old version of Twisted < 24.7.0')
    _canonicalHeaderName = Headers()._canonicalNameCaps  # type: ignore[attr-defined]
elif hasattr(Headers, "_encodeName"):
    logger.warning(f'you appear to be running an old version of Twisted 24.7.0')
    # But note that `_encodeName` still exists on prior versions,
    # it just encodes differently
    _canonicalHeaderName = Headers()._encodeName
else:
    logger.warning(f'you appear to be at an unsupported version of Twisted')
    _canonicalHeaderName = 'foo.name'
phreed commented 1 week ago

As you can see _encodeName was part of the private API. https://docs.twisted.org/en/twisted-24.7.0/api/twisted.web.http_headers.Headers.html?private=1

It is removed in the 24.10.0 https://docs.twisted.org/en/twisted-24.10.0/api/twisted.web.http_headers.Headers.html?private=1

I think the intent is to use the str function instead.

villepeh commented 1 week ago

Can confirm the issue. I downgraded Twisted and Synapse works again.

dillfrescott commented 1 week ago

Running into this issue as well, prevents synapse from starting. (Synapse 1.118.0)

dillfrescott commented 1 week ago

Can confirm downgrading to the last version of Twisted remedies the issue

Josue-T commented 1 week ago

Same issue on my side, downgrade also fixed the issue.

arkamar commented 1 week ago

It is currently also related to https://github.com/element-hq/synapse/issues/17075.