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

MatrixClient.setAccountData: await remote echo. #4695

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Feb 5, 2025

Wait for the echo to come back from the server before we assume the account data has been successfully set.

We have a bit of a problem in the dehydration setup code in that it calls bootstrapSecretStorage and, not unreasonably, expects isSecretStorageReady to return true. Currently, it doesn't, because isSecretStorageReady checks the in-memory account data cache, which isn't updated until the echo comes back down /sync.

So, the thing to do seems to be to wait for the echo to come back before proceeding. But I'm not really sure where this fits best: I considered putting it in ServerSideSecretStorageImpl or even bootstrapSecretStorage, but it really feels like this is a wider problem than just secret storage.

src/client.ts Outdated
//
// NB that we rely on this operation being synchronous to avoid a race condition: there must be no `await`
// between here and `this.addListener` below, in case we miss an update.
if (JSON.stringify(this.store.getAccountData(eventType)) === JSON.stringify(content)) return {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't guaranteed to work, given the keys aren't being sorted. The key order is based on insertion order for string keys, so will map to JSON-order for JSON-originating content, but for the content provided by the caller that order may not match.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh, true. I guess we need canonical json, or something

@richvdh richvdh force-pushed the rav/await_accountdata_echo branch from 84ca831 to ac95231 Compare February 7, 2025 16:51
use fetch-mock rather than whatever this was
@richvdh richvdh force-pushed the rav/await_accountdata_echo branch from ac95231 to c0d59bb Compare February 7, 2025 17:00
Wait for the echo to come back from the server before we assume the account
data has been successfully set
@richvdh richvdh force-pushed the rav/await_accountdata_echo branch from c0d59bb to 78df5c8 Compare February 10, 2025 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants