---
# System prepended metadata

title: Login Problem
tags: [Lale, Synapse, Matrix]

---

# Login Problem 
###### tags: `Lale` `Matrix` `Synapse`
**Date:** 2021/07/22 

**Lale has a login problem for certain users. In this case `@laleton.eden999:lalepass.lale.im` can't log in from any device and with any fashion!**



## Login Response 

The following are several login responses from client apps and  Auth Types. 

* **Android**
After login keeps loading and never finish, stuck and crash. 

* **Element**
Client can't reach homeserver properly. 

* **Lalepass**
No response after login 

* **Python SDK**
Keep looping and never end. 

* **Matrix API** 
Nginx timeout can't a get response from Matrix synapse. 
![(Error API)](../media/img/LALE_TEST/user_login/nginx_error.png)


## Problem 
* `@laleton.eden999` has more than **137k** rooms. 
* The matrix synapse failed to response in 300 seconds. 
* This is because there are too much data to be sync for `@laleton.eden999`


## First Attempt
* We use the filter API on synapse to limit the number of data being sync for each user. 
* We use the following API to create the filter for user `@laleton.eden999:lalepass.im`

`POST /_matrix/client/r0/user/{userId}/filter`

Please refer to the following [link](https://matrix.org/docs/spec/client_server/r0.3.0#post-matrix-client-r0-user-userid-filter) for further detail about the API.

* So far we have succeeded to add filter for a certain user. 
* But the `@laleton.eden999::lalepass.im` is still unable to log in. 
* I tried to create a filter for other users and the filter success and working properly. 
![(Sync without filter)](../media/img/LALE_TEST/user_login/the_filter_is_work2.png)
![(Sync with filter)](../media/img/LALE_TEST/user_login/the_filter_is_work1.png)


We may use this filter to **speed up the sync time**, for example, we can use the full `/sync` at the **startup** (client apps). But, while the client app open, we use the `/sync` with **filter**.   
<p>&nbsp;</p>

## Testing on Different Server (Migration Data Problem)

**Date:** 2021/07/26  

* I continued to test using the `filter`, but when I test on production **SERVER**. the server becomes slow and some users can't log in (not sure if it is because of Eden999 activities). 
* So, I plan to move my testing process to the `laledev6.flowring.com` server. 
* The basic problem is **the scalability of the matrix server**, `lalenton.eden999` can't login because it has **too many rooms (~137k rooms)**. So, I need to copy all the production data to the dev2 server (test server). 
* The data size is 4.3GB in sql.gz (estimated  ~20GB in raw SQL plain text). 
* I tried to restore the data to the dev6 server but failed, due to **not having enough space**. 

![not enough space](../media/img/LALE_TEST/user_login/not_enough_space.png)
![df_h](../media/img/LALE_TEST/user_login/df_h.png)

* Because the Laledev6 has a problem, so I decide to test in `the devmtx2.lalepas.im` server
* I tried to copy & dump the data using pg_dump from the **Dev6 server but also failed**, because there is **no space**. So pg_dump can't work. 
* So I use PgAdmin to download the Dev6.laledb data to **my local computer**.
* It is successful in backup the Dev6.laledb from Dev6 in ~100seconds. The size is 120MB in raw SQL.
* Restore to the **Server Dev2 (devmtx2.laledb3)**, it takes ~5minutes.
* The matrix in Dev2 **can't connect** to the new database. because we can't change the server name. (that is the design of the matrix), and also the different table scheme (devmtx2 Matrix using scheme version 59).
* So, the only way is to **change all the `server name` in the DB**.

* **if the pg_dump is work normally and the postgres are having the same version, I suggest using pg_dump to directly copy the data (without dump or backup or export)** 
Ref for : [remote migrate](https://stackoverflow.com/questions/1237725/copying-postgresql-database-to-another-server)

### Some problem and difficulties: 

* There are so many fields in the database that contain the `server_name`, I need to **change all of them**.
* We don't know which fields contain `server_name`. so we need to go through **213 tables** and check which fields need to be changed.
* Then we create query to replace the `server_name`.
* eventually, we still need to do this if we want to upgrade the matrix server.
* I estimate the raw SQL in the production server is around ~20GB.
* If everything goes smoothly the migration will take 17 hours.
* Then running the server name replacement (We still don't know how long does it take to run the query for that. )



### Propose solution for login problem. 
1. I proposed to lower the `filter_timeline_limit` in the matrix configuration.
2. some people had the problems before

[Sync problem 1](https://github.com/YunoHost-Apps/synapse_ynh/issues/257)

[Sync problem 2](https://github.com/vector-im/element-android/issues/983)

[Sync problem 3](https://github.com/matrix-org/synapse/issues/9264)

3. some people login successfully after change the `filter_timeline_limit`
4. in the newer matrix versions, they set the default `filter_timeline_limit = 100`. 

This is the pull request (on Jul 17, 2020)
[Pull request & merge: Matrix change filter_timeline_limit from -1 to 100](https://github.com/matrix-org/synapse/pull/7858/files)


### Todo

**If my proposal is accepted, here is the steps** 
1. Open homeserver.yaml in the `lalepass.lale.im` server. 
2. Uncomment `filter_timeline_limit` in line 105 
3. Change the value to 25. `filter_timeline_limit: 25`
4. Restart the Matrix Service. 
5. Try login using `@laleton.eden999:lalepass.lale.im`



### Filtering Doesn't work 
**Date:** 2021/07/28

We still face difficulty on matrix scalability. 
1. If a user has too many rooms. It causes a login/sync problem. 
2. We try to set timeline_limit but Doesn't work, because still too many rooms. 
3. We also try Filtering API but doesn't work as well. 