element-hq / element-hq/element-android
Discovery order for homeserver causes "network errors"
- Dominant language
- Kotlin
- Stars
- 3.7k
- Forks
- 917
- PR merge metrics
- No merged PRs in 30d
Description
#### Describe the bug
When trying to set up element-android with my homeserver via the "other" functionality using the base url always yielded a "No network. Please check your internet connection." However, when testing with another homeserver I got to the login prompt.
Also in the webserver logs I could see a request to `GET /_matrix/client/versions HTTP/2.0`.
For reference (and to check I'm not insane I also tested my homeserver against app.element.io. The discovery was successful.
After looking at the request and the responses in android studio and comparing it to the other homeserver which did connect successfully I noted this difference:
```
V/FormattedJsonHttpLogger: --> GET https://other-home.server/_matrix/client/versions
V/FormattedJsonHttpLogger: <-- 404 https://www.other-home.server/_matrix/client/versions (368ms, unknown-length body)
W/RetrofitExtensionsKt: The error returned by the server is not a MatrixError
E/Request: Exception when executing request GET https://other-home.server/_matrix/client/versions
V/FormattedJsonHttpLogger: --> GET https://other-home.server/config.other-home.server.json
V/FormattedJsonHttpLogger: <-- 404 https://www.other-home.server/config.other-home.server.json (220ms, unknown-length body)
W/RetrofitExtensionsKt: The error returned by the server is not a MatrixError
E/Request: Exception when executing request GET https://other-home.server/config.other-home.server.json
V/FormattedJsonHttpLogger: --> GET https://other-home.server/config.json
V/FormattedJsonHttpLogger: <-- 404 https://www.other-home.server/config.json (214ms, unknown-length body)
W/RetrofitExtensionsKt: The error returned by the server is not a MatrixError
E/Request: Exception when executing request GET https://other-home.server/config.json
V/FormattedJsonHttpLogger: --> GET https://other-home.server/.well-known/matrix/client
V/FormattedJsonHttpLogger: <-- 200 https://other-home.server/.well-known/matrix/client (96ms, 81-byte body)
V/FormattedJsonHttpLogger: --> GET https://matrix.other-home.server/_matrix/client/versions
V/FormattedJsonHttpLogger: <-- 200 https://matrix.other-home.server/_matrix/client/versions (216ms, unknown-length body)
V/FormattedJsonHttpLogger: --> GET https://matrix.other-home.server/_matrix/client/versions
V/FormattedJsonHttpLogger: <-- 200 https://matrix.other-home.server/_matrix/client/versions (159ms, unknown-length body)
V/FormattedJsonHttpLogger: --> GET https://matrix.other-home.server/_matrix/client/r0/login
V/FormattedJsonHttpLogger: <-- 200 https://matrix.other-home.server/_matrix/client/r0/login (27ms, unknown-length body)
```
In comparison my failing connection looked like this
```
V/FormattedJsonHttpLogger: --> GET https://MYDOMAIN/_matrix/client/versions
V/FormattedJsonHttpLogger: <-- 200 https://other.MYDOMAIN/ (374ms, unknown-length body)
E/Request: Exception when executing request GET https://MYDOMAIN/_matrix/client/versions
```
This was related to the configuration of the webserver which redirected all except for the well-kown lookup to `other`.
Apparently this crashes the entire lookup.
The workaround was to effectively blackhole the other lookup urls and return 404 instead.
#### To Reproduce
1. Set up a homeserver on some subdomain and a base_url different to that subdomain
2. In the reverse proxy configure the base domain server
3. create a location for the well-known endpoint as described in the [Installation guide](https://github.com/matrix-org/synapse/blob/master/INSTALL.md#client-well-known-uri)
4. Forward all other requests somewhere else
5. try to configure element-android for the new homeserver
#### Expected behavior
Element should discover the homeserver base url from `/.well-known/matrix/client` as app.element.io when the reverse proxy for the base url only serves the ``well-known` endpoint and forwards all other requests somewhere else.
#### Smartphone (please complete the following information):
- Android Studio Emulator (Android 9):
```
Name: Nexus_S_API_28
CPU/ABI: Google APIs Intel Atom (x86)
Target: google_apis [Google APIs] (API level 28)
```
- One Plus 3 (Android 9)
- Nexus_5_API_30 (Android K)
#### Additional context
- Occurs in latest play store app and local checkout of v1.1.3 as well as latest develop ( 2df8eb199b6e2b1f857f632dae48747de89f0a97 )
Contributor guide
Assessment
This issue has not been assessed yet.