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

Create Room Client API Fails with { errcode: 'M_UNKNOWN', error: 'Internal server error' } #13482

Closed
andreidiaconescu opened this issue Aug 9, 2022 · 5 comments
Labels
T-Other Questions, user support, anything else.

Comments

@andreidiaconescu
Copy link

andreidiaconescu commented Aug 9, 2022

Description

Hello,
i am trying to create a room using the API call:

http://synapse:8008/_matrix/client/v3/createRoom?user_id=@ge1jpwwv9dtu2wrvfdm:matrix.connectme.anais.tech

I am using the headers:

{
    Accept: 'application/json',
    'Content-Type': 'application/json',
    Authorization: 'Bearer the_app_service_token'
}

The token is an application server token.

The response is:

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

Steps to reproduce

  • API Url:
http://synapse:8008/_matrix/client/v3/createRoom?user_id=@ge1jpwwv9dtu2wrvfdm:matrix.connectme.anais.tech
  • headers
{
    Accept: 'application/json',
    'Content-Type': 'application/json',
    Authorization: 'Bearer 30c05ae90a248a4188e620216fa72e349803310ec83e2a77b34fe90be6081f46'
}
  • The token is an application server token.

  • The response is:

{ errcode: 'M_UNKNOWN', error: 'Internal server error' }
  • In the terminal logs i see an error:
synapse_1     | 2022-08-09 08:32:32,651 - synapse.http.server - 183 - ERROR - POST-19 - Failed handle request via 'RoomCreateRestServlet': <XForwardedForRequest at 0x7f3de09ce970 method='POST' uri='/_matrix/client/v3/createRoom?user_id=@ge1jpwwv9dtu2wrvfdm:matrix.connectme.anais.tech' clientproto='HTTP/1.1' site='8008'>
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/twisted/internet/defer.py", line 1660, in _inlineCallbacks
    result = current_context.run(gen.send, result)
  StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 File "/usr/local/lib/python3.9/site-packages/synapse/http/server.py", line 366, in _async_render_wrapper
    callback_return = await self._async_render(request)
  File "/usr/local/lib/python3.9/site-packages/synapse/http/server.py", line 572, in _async_render
    callback_return = await raw_callback_return
  File "/usr/local/lib/python3.9/site-packages/synapse/rest/client/room.py", line 91, in on_POST
    info, _ = await self._room_creation_handler.create_room(
  File "/usr/local/lib/python3.9/site-packages/synapse/handlers/room.py", line 877, in create_room
    initial_state[(val["type"], val.get("state_key", ""))] = val["content"]
KeyError: 'content'
 2022-08-09 08:32:32,656 - synapse.access.http.8008 - 450 - INFO - POST-19 - ::ffff:172.24.0.2 - 8008 - {@ge1jpwwv9dtu2wrvfdm:matrix.connectme.anais.tech} Processed request: 0.014sec/0.001sec (0.001sec, 0.003sec) (0.001sec/0.006sec/6) 55B 500 "POST /_matrix/client/v3/createRoom?user_id=@ge1jpwwv9dtu2wrvfdm:matrix.connectme.anais.tech HTTP/1.1" "-" [0 dbevts]

Homeserver

A Synapse server i installed locally

Synapse Version

{"server_version":"1.61.1","python_version":"3.9.13"}

Installation Method

Docker (matrixdotorg/synapse)

Platform

Ubuntu running docker, and in docker Synapse is running.

Relevant log output

Traceback (most recent call last):
 File "/usr/local/lib/python3.9/site-packages/synapse/http/server.py", line 366, in _async_render_wrapper
    callback_return = await self._async_render(request)
  File "/usr/local/lib/python3.9/site-packages/synapse/http/server.py", line 572, in _async_render
    callback_return = await raw_callback_return
  File "/usr/local/lib/python3.9/site-packages/synapse/rest/client/room.py", line 91, in on_POST
    info, _ = await self._room_creation_handler.create_room(
  File "/usr/local/lib/python3.9/site-packages/synapse/handlers/room.py", line 877, in create_room
    initial_state[(val["type"], val.get("state_key", ""))] = val["content"]
KeyError: 'content'
 2022-08-09 08:32:32,656 - synapse.access.http.8008 - 450 - INFO - POST-19 - ::ffff:172.24.0.2 - 8008 - {@crx66ctg69h32rv55mr3gd1n5mu3arb25nh3ce325ngk0ctn60up4c1h6hhk2ek7c5h74ub5dh066vvge1jpwwv9dtu2wrvfdm:matrix.connectme.anais.tech} Processed request: 0.014sec/0.001sec (0.001sec, 0.003sec) (0.001sec/0.006sec/6) 55B 500 "POST /_matrix/client/v3/createRoom?user_id=@ge1jpwwv9dtu2wrvfdm:matrix.connectme.anais.tech HTTP/1.1" "-" [0 dbevts]


### Anything else that would be useful to know?

_No response_
@DMRobertson
Copy link
Contributor

The token is an application server token.

Please note that you've posted the token publicly. If your application service is configured correctly, this token should only be accepted from trusted, private IP addresses and not the public web. I'd recommend invalidating and generating a new token out of caution.

KeyError: 'content'

This suggests you have provided an initial_state in the body of the POST .../createRoom request, but have not provided a content for some of the state events. Can you share the body of the POST request as well please?

Related: #13147 would give us a better error message here.

@DMRobertson DMRobertson added T-Other Questions, user support, anything else. X-Needs-Info This issue is blocked awaiting information from the reporter labels Aug 9, 2022
@DMRobertson
Copy link
Contributor

See also the spec's description of /createRoom: https://spec.matrix.org/v1.3/client-server-api/#post_matrixclientv3createroom

@andreidiaconescu
Copy link
Author

Hello,

The post content sent to the API to create a room is (inspired from https://spec.matrix.org/v1.3/client-server-api/#post_matrixclientv3createroom):

{
"creation_content":{"m.federate":false},
"initial_state":[{}],
"name":"ntestabc",
"preset":"public_chat",
"room_alias_name":"ltestabc",
"room_version":"9",
"topic":"Topic Room 1 to 1 qwe to asd"
}

@andreidiaconescu
Copy link
Author

andreidiaconescu commented Aug 9, 2022

I removed the initial_state key from the post data:

{
"creation_content":{"m.federate":false},
"name":"ntestabc",
"preset":"public_chat",
"room_alias_name":"ltestabc",
"room_version":"9",
"topic":"Topic Room 1 to 1 qwe to asd"
}

And now i get as result:

{
  room_id: '!VkdeieODyBHeTJjTUC:..............',
  room_alias: '#Room_1_to_1_.................'
}

But still there appears a new error in the terminal:

 2022-08-09 10:09:55,735 - synapse.appservice.scheduler - 426 - ERROR - as-sender-app_service-0 - Error starting AS recoverer
 Traceback (most recent call last):
   File "/usr/local/lib/python3.9/site-packages/twisted/internet/defer.py", line 1660, in _inlineCallbacks
     result = current_context.run(gen.send, result)
 StopIteration: True
 
 During handling of the above exception, another exception occurred:
 
 Traceback (most recent call last):
   File "/usr/local/lib/python3.9/site-packages/synapse/appservice/scheduler.py", line 424, in _on_txn_fail
     self.start_recoverer(service)
   File "/usr/local/lib/python3.9/site-packages/synapse/appservice/scheduler.py", line 435, in start_recoverer
     assert service.id not in self.recoverers
 AssertionError

i think the last error is due to the url of the Application service not being good,
so i guess creating the room works fine.

Thank you.

@richvdh
Copy link
Member

richvdh commented Aug 9, 2022

Glad you fixed the original issue - as you discovered, it was because the initial_state property contained an invalid entry.

If you're unable to solve the new problem, please open a separate issue.

@richvdh richvdh closed this as completed Aug 9, 2022
@DMRobertson DMRobertson removed the X-Needs-Info This issue is blocked awaiting information from the reporter label Aug 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Other Questions, user support, anything else.
Projects
None yet
Development

No branches or pull requests

3 participants