Skip to content

fix: concurrent remote key queries failing with 503 - #20597

Open
FrenchGithubUser wants to merge 1 commit into
element-hq:developfrom
famedly:tt/concurrent-device-query-2
Open

FrenchGithubUser wants to merge 1 commit into
element-hq:developfrom
famedly:tt/concurrent-device-query-2

Conversation

@FrenchGithubUser

Copy link
Copy Markdown
Contributor

Two concurrent /keys/query requests for the same uncached remote user race: the first triggers a device-list resync, the second blocks on the per-user linearizer, and by the time it acquires the lock the device cache is valid. That cached path returned the raw cache mapping ({device_id: content}) rather than a federation-shaped response, so the caller's resync_results["devices"] raised KeyError. A single user's KeyError was converted into a 503 for the entire remote server and every other user in the query failed too.

The fix rebuilds a proper federation-shaped result on the cached path, with a TypedDict setting the shape so both paths stay in sync.

While doing that, a second instance of the same pattern was found: it also did device["keys"] unguarded, but Synapse omits keys entirely for devices that have never uploaded any, so one keyless remote device would also respond with 503. This path is also fixed.

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct (run the linters)

@FrenchGithubUser
FrenchGithubUser requested a review from a team as a code owner December 3, 2026 12:07
@FrenchGithubUser
FrenchGithubUser requested review from erikjohnston and removed request for a team December 3, 2026 12:07

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant