matrix-org / synapse

Synapse: Matrix homeserver written in Python/Twisted.
https://matrix-org.github.io/synapse
Apache License 2.0
11.79k stars 2.13k forks source link

Internal server error when using List Room API with no filtering #8188

Closed anthr76 closed 4 years ago

anthr76 commented 4 years ago

Description

When requesting all rooms in your home server via admin API the following response is sent.

{
    "errcode": "M_UNKNOWN",
    "error": "Internal server error"
}

Steps to reproduce

This seems like it's an issue having emojis in the room names. When using a search term to narrow down the results the issue doesn't show up.

A traceback in synpase logs show:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/synapse/http/server.py", line 233, in _async_render_wrapper
    self._send_response(request, code, response)
  File "/usr/local/lib/python3.7/site-packages/synapse/http/server.py", line 295, in _send_response
    canonical_json=self.canonical_json,
  File "/usr/local/lib/python3.7/site-packages/synapse/http/server.py", line 536, in respond_with_json
    json_bytes = encode_pretty_printed_json(json_object) + b"\n"
  File "/usr/local/lib/python3.7/site-packages/canonicaljson.py", line 96, in encode_pretty_printed_json
    return _pretty_encoder.encode(json_object).encode("ascii")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 10427-10428: ordinal not in range(1
28)

Some rooms not in my server but are federated by my server have emojis in the name. Which show up in the logs:

...'name': 'šŸ”Š Audio Corner', 'canonical_alias': '#audiocorner:jupiterbroadcasting.com', 'joined_members': 39, 'joined_local_members': 1, 'version': '5', 'creator': '', 'encryption': None, 'federatable': True, 'public': ...

Version information

If not matrix.org: matrix.rabbito.tech


- **Install method**:
<!-- examples: package manager/git clone/pip  -->
matrixdotorg docker container

- **Platform**:
<!--
Tell us about the environment in which your homeserver is operating
distro, hardware, if it's running in a vm/container, etc.
-->
Containerized on Ubuntu 20.04 LTS
clokep commented 4 years ago

This sounds like the same as matrix-org/python-canonicaljson#33 -- a workaround is to specify a user-agent which isn't curl.

anthr76 commented 4 years ago

This workaround succeeded !

clokep commented 4 years ago

Glad that worked! We'll need to release a new version of canonicaljson at some point with the fix in it. šŸ‘

clokep commented 4 years ago

FYI we released an update for python-canonicaljson which should fix this. You can install 1.4.0 and it should work fine!

richvdh commented 4 years ago

see also #8262 which adds a dependency on canonicaljson 1.4.0, so people upgrading to synapse 1.21.0 will automatically get this fix.