element-android icon indicating copy to clipboard operation
element-android copied to clipboard

Cannot init sync

Open catfromplan9 opened this issue 2 years ago • 4 comments

Steps to reproduce

  1. Where are you starting? What can you see? I unignored an account and clicked ok to init sync
  2. What do you click? Nothing, just open the app
  3. More steps… Sometimes after unignoring someone and doing init sync, it works, but if I've changed my account avatar prior to the last init sync it'll do this. It used to just take 10 or 15 minutes, now it is indefinite. And no, I don't have that much account data cause when I login using fresh element install it takes 5 seconds to init sync

Outcome

What did you expect?

I expect for init sync to work like it does on first install, where everything syncs my account completely fine.

What happened instead?

It says loading account, that works, then it says "Loading your conversations" and gets stuck there. It does not progress no matter what I do, but it'll work fine if I reinstall and add my account again though that is a bit tedious.

Your phone model

Pixel 5a

Operating system version

Android 13.0

Application version and app store

Element 1.5.18, olm 3.2.12. Google Play Store

Homeserver

Synapse 1.74.0

Will you send logs?

Yes

Are you willing to provide a PR?

No

catfromplan9 avatar Jan 10 '23 15:01 catfromplan9

We had recent issue with initial sync, but on 1.5.18 it should be fine. When you perform a clear cache from Settings/General, do you observe the same issue?

bmarty avatar Jan 10 '23 15:01 bmarty

Yes, I rebooted and restarted app too. Only fix I found was reinstall, and as I mentioned I can init sync fast after initial login so it's not a server issue

catfromplan9 avatar Jan 10 '23 16:01 catfromplan9

Seems to be that it works fine until I change my avatar or display name. At that point, the next init sync will fail. It'll finish downloading the init sync data almost immediately but it'll just get stuck loading convos as I said. It could be some failure with handling the avatar or displayname change that is being processed in every room, but then I wonder why this wasn't found and patched earlier.

catfromplan9 avatar Jan 18 '23 09:01 catfromplan9

Have the same issue with Element Android 1.6.42. I took a closer look at the response content of /_matrix/client/r0/sync?filter=0&set_presence=offline&timeout=0 and found that the server was inserting incorrect values in events (see errcode and error):

{
    "next_batch": "s5680270_26685287_4_753634_1150132_826_1346_7412_0_1",
    "account_data": {
        "events": [
            {
                "type": "m.direct",
                "content": {
                    "errcode": "M_NOT_FOUND",
                    "error": "Account data not found",
                    "@***:matrix.***.******": [
                        "!HeoBHytXqNISAudhlb:matrix.***.******"
                    ],
                    "@***:matrix.***.******"": [
                        "!gWTukmRnZguxoPeRdy:matrix.***.******"
                    ],
                    "@***:matrix.***.******"": [
                        "!rYUOquPWkZrfrhPEZu:matrix.***.******"
                    ],
                    "@***:matrix.***.******"": [
                        "!ruMkbglNytWnzrCoGu:matrix.***.******"
                    ],
                    "@***:matrix.***.******"": [
                        "!QLwPkAGBIVsjxEwvXu:matrix.***.******"
                    ]
                }
            },
…

I ran the app in debug mode and get the following error in logcat:

## Sync: sync service did fail true
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
    at org.matrix.android.sdk.internal.session.sync.handler.UserAccountDataSyncHandler.handleDirectChatRooms(UserAccountDataSyncHandler.kt:174)
    at org.matrix.android.sdk.internal.session.sync.handler.UserAccountDataSyncHandler.handle(UserAccountDataSyncHandler.kt:89)
    at org.matrix.android.sdk.internal.session.sync.SyncResponseHandler.handleAccountData(SyncResponseHandler.kt:241)
    at org.matrix.android.sdk.internal.session.sync.SyncResponseHandler.access$handleAccountData(SyncResponseHandler.kt:52)
    at org.matrix.android.sdk.internal.session.sync.SyncResponseHandler$startMonarchyTransaction$2$1.invoke(SyncResponseHandler.kt:207)
    at org.matrix.android.sdk.internal.session.sync.SyncResponseHandler$startMonarchyTransaction$2$1.invoke(SyncResponseHandler.kt:204)
    at org.matrix.android.sdk.internal.database.AsyncTransactionKt$awaitTransaction$2.invokeSuspend(AsyncTransaction.kt:46)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:919)

To solve this, I manually edited the account_data table in the Matrix Synapse database by removing the incorrect values from the JSON in the content field:

UPDATE account_data
SET "content" = ("content"::jsonb - 'error' - 'errcode')::text
WHERE account_data_type = 'm.direct' AND ("content"::jsonb ->> 'error' IS NOT NULL OR "content"::jsonb ->> 'errcode' IS NOT NULL)

It would be a good idea to validate the m.direct contents on the client side.

drygdryg avatar Jul 04 '25 15:07 drygdryg