Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client very slow to restore session after Rust crypto v8 → v10 migration #26948

Closed
robintown opened this issue Jan 31, 2024 · 12 comments · Fixed by matrix-org/matrix-js-sdk#4060
Assignees
Labels
A-Element-R Issues affecting the port of Element's crypto layer to Rust O-Occasional Affects or can be seen by some users regularly or most users rarely S-Critical Prevents work, causes data loss and/or has no workaround T-Defect Z-Labs

Comments

@robintown
Copy link
Member

Steps to reproduce

  1. Be on develop.element.io, refresh to update your client
  2. Notice that it's taking a really long time to load
  3. Open the console and find that a Rust crypto migration is in progress

Outcome

What did you expect?

The migration should finish and I should be able to use my client again.

What happened instead?

After migrating all 80000-something sessions, it outputs a message to say it's now migrating the schema. At this point my CPU goes idle and no further interesting logs appear, so the client appears to be stuck on the loading screen. I refresh the page and the client now fails to start with an error in the console about failing to connect to IndexedDB.

Operating system

NixOS unstable

Browser information

Firefox 121.0.1

URL for webapp

develop.element.io

Application version

7c584df-react-a3a387a1dd8f-js-d178fbf9cdc3

Homeserver

Synapse 1.99.0

Will you send logs?

Yes

@robintown robintown added T-Defect S-Critical Prevents work, causes data loss and/or has no workaround A-Element-R Issues affecting the port of Element's crypto layer to Rust labels Jan 31, 2024
@andybalaam andybalaam self-assigned this Feb 1, 2024
@andybalaam
Copy link
Member

I get the same behaviour, and so does Valère. Investigating.

@andybalaam
Copy link
Member

The scheme upgrade in question only deletes the old object store, nothing else.

A stackoverflow page suggests that you need to clear() an object store before deleting it, but we have not done this in the past and it worked fine.

@BillCarsonFr
Copy link
Member

I waited instead of refreshing, and it finally completed:

https://rageshakes.element.io/api/listing/2024-02-01/102737-F7T44FAH/logs-0000.log.gz

2024-02-01T08:17:05.339Z I INFO matrix_sdk_indexeddb::crypto_store::migrations::v8_to_v10: IndexeddbCryptoStore upgrade schema -> v10 starting

and after 2 hours??

2024-02-01T10:23:27.105Z I INFO matrix_sdk_indexeddb::crypto_store::migrations::v8_to_v10: IndexeddbCryptoStore upgrade schema -> v10 complete

@BillCarsonFr
Copy link
Member

BillCarsonFr commented Feb 1, 2024

Also it is now re-uploading all my keys to backup?
But maybe it's because my 4S is desynced

2024-02-01T10:23:27.763Z D Backup: Starting keys upload loop for backup version:83.
2024-02-01T10:23:27.953Z D FetchHttpApi: <-- GET https://matrix-client.matrix.org/_matrix/client/v3/room_keys/version [191ms 200]
2024-02-01T10:23:27.954Z D [PerSessionKeyBackupDownloader] Got current backup version from server: 83
2024-02-01T10:23:27.955Z D [PerSessionKeyBackupDownloader] Version for which we have a decryption key (82) doesn't match the version we are backing up to (83)

@andybalaam andybalaam changed the title Client fails to restore session after Rust crypto v8 → v10 migration Client very slow to restore session after Rust crypto v8 → v10 migration Feb 1, 2024
@andybalaam
Copy link
Member

Since it eventually worked for @BillCarsonFr I changed the description of this PR to say it was very slow rather than failed.

I have a client that I refreshed part-way, and it is now being very slow to start, so we will see whether it leaves people's clients in a broken state.

@robintown were you able to use Element after refreshing?

@andybalaam
Copy link
Member

I have a client that I refreshed part-way, and it is now being very slow to start, so we will see whether it leaves people's clients in a broken state.

Yes, it worked eventually but it took a long time (over an hour?)

@andybalaam
Copy link
Member

I'm going to benchmark creating a lot of records and dropping the store, to see whether this is a general problem, or caused by a particular bug in our code.

@robintown
Copy link
Member Author

@andybalaam were you able to use Element after refreshing?

No, that client is still unable to restore the session

@robintown robintown added the O-Occasional Affects or can be seen by some users regularly or most users rarely label Feb 1, 2024
@andybalaam
Copy link
Member

No, that client is still unable to restore the session

@robintown please leave it running. After refresh, mine printed nothing for a long time, and then eventually it worked. (Took about 1-2 hours)

@andybalaam
Copy link
Member

I now strongly suspect this is Firefox-only. I am able to reproduce slowness to delete a large store with an index in Firefox, but it's fine in Chrome.

@andybalaam
Copy link
Member

This is a problem in Firefox, which I have documented here: https://www.artificialworlds.net/blog/2024/02/02/deleting-an-indexed-db-store-can-be-incredibly-slow-on-firefox/

I will log a bug against Firefox if one doesn't already exist.

@andybalaam
Copy link
Member

This PR: matrix-org/matrix-rust-sdk#3090 should speed things up by about 3 times on Firefox, but I think that is all we can do.

andybalaam added a commit to matrix-org/matrix-rust-sdk-crypto-wasm that referenced this issue Feb 5, 2024
Including getting the latest matrix-rust-sdk, providing:

* [indexeddb: Clear the object store before deleting it #3090](matrix-org/matrix-rust-sdk#3090)

which speeds up the schema upgrade v8 to v10 (see
element-hq/element-web#26948 ).
andybalaam added a commit to matrix-org/matrix-js-sdk that referenced this issue Feb 5, 2024
andybalaam added a commit to matrix-org/matrix-js-sdk that referenced this issue Feb 5, 2024
andybalaam added a commit to matrix-org/matrix-js-sdk that referenced this issue Feb 5, 2024
andybalaam added a commit to matrix-org/matrix-js-sdk that referenced this issue Feb 6, 2024
andybalaam added a commit to matrix-org/matrix-rust-sdk-crypto-wasm that referenced this issue Feb 7, 2024
andybalaam added a commit to matrix-org/matrix-js-sdk that referenced this issue Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Element-R Issues affecting the port of Element's crypto layer to Rust O-Occasional Affects or can be seen by some users regularly or most users rarely S-Critical Prevents work, causes data loss and/or has no workaround T-Defect Z-Labs
Projects
None yet
3 participants