matrix-org / matrix-org/matrix-rust-sdk

Replace the `TtlStoreValue` type on cached Versions/WellKnown with background refreshes.

Open
#6,090 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.3k
Forks
500
Avg merge
1d 16h
Merged PRs (30d)
106

Description

We've keep tripping over this expiration in different places so it's time to fix it. Some examples have been:

  • Conflicts between refreshing versions and refreshing the access token #5822 #5825 #5853 #5916
  • Changes to the well-known's rtc_foci taking up to 7 days to be picked up by clients (admittedly we should be using the newer CS API endpoint for this now, but that would still involve caching a value) which became even more apparent after #5996 which had no immediate effect unless the cache was cleared.
  • Discovered today: SyncServiceBuilder::build can fail with network related errors such as DNS resolution/Timeouts/Temporary server errors when checking server support for thread subscriptions. If we want good offline support in the SDK (and to handle poor connections gracefully) a Client and its associated services should really not be making network requests to be built and supply already cached data.

The solution (already been discussed with @bnjbvr a week or two ago) would be to remove TtlStoreValue and it's STALE_THRESHOLD and always return the cached value. Alongside this, we would need a mechanism that would make the relevant API calls in the background, caching any valid responses so that the next read is up to date. These background refreshes should ideally wait until any sync loops are running and up-to-date to avoid slowing down initial syncs and at the very least should be scheduled every time a Client is created (although ideally using something like SyncService::start to schedule the refreshes would help long-lived Clients to stay more up to date as apps get backgrounded and foregrounded).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading TtlStoreValue and STALE_THRESHOLD in crates/matrix-sdk-base/src/store/traits.rs, then trace SyncServiceBuilder::build and SyncService::start. Define how cached Versions and WellKnown are returned without expiration and how background refreshes are scheduled after sync or Client creation; done means valid responses refresh the cache without making Client or associated services fail on network errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.