element-hq / element-hq/synapse
Identity server errors during 3PID invite cause 500 internal server error
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 600
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 51
Description
### Description
When an identity server returns a non-2xx response (my case: 400, `M_THREEPID_IN_USE`) to Synapse's `/store-invite` request during a 3PID invite, Synapse returns a 500 internal server error with `M_UNKNOWN` instead of handling the error and returning an appropriate 4xx response. Because the server always returns a generic 500 `M_UNKNOWN` here, it’s difficult for clients to implement good UX for this case.
### Steps to reproduce
- Make the identity server return 400 for /store-invite requests
- Do the request
- Synapse returns a 500 internal server error with `M_UNKNOWN` instead of handling the identity server's error response.
### Homeserver
On private homeserver
### Synapse Version
1.140.0
### Installation Method
Other - Helm chart
### Database
PostgreSQL 17.6
are you using a single PostgreSQL server or [separate servers for main and state](https://element-hq.github.io/synapse/latest/usage/configuration/config_documentation.html#databases)?
**Single**
have you previously ported from SQLite using the Synapse "portdb" script?
**No**
have you previously restored from a backup?
**No**
### Workers
Multiple workers
### Platform
In self-managed k8s in Ubuntu 24.04.3 VM (AMD) cluster
### Relevant log output
```shell
{"log":"Failed handle request via 'RoomMembershipRestServlet': ","namespace":"synapse.http.server","level":"ERROR","time":1764584153.74,"request":"POST-1566538","server_name":"homeserver.xx","ip_address":"11.11.11.11","site_tag":"8083","requester":"@65349:homeserver.xx","authenticated_entity":"@65349:homeserver.xx","method":"POST","url":"/_matrix/client/v3/rooms/!SFSEJVodkvUDxGipWt%3Ahomeserver.xx/invite","protocol":"HTTP/1.1","user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36","exc_type":"HttpResponseException","exc_value":"400: Bad Request"}
```
Contributor guide
Research direction
Start at the RoomMembershipRestServlet entry point from the log and trace handling of the identity server's /store-invite response when it returns 400 M_THREEPID_IN_USE. Reproduce the request with a non-2xx identity-server response and determine the expected 4xx response instead of 500 M_UNKNOWN. Done means this failure is handled appropriately and covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100