Skip to content

fix: presence stream stalling intermittently - #20090

Merged
sandhose merged 2 commits into
element-hq:developfrom
famedly:tt/fix-presence-stream
Aug 13, 2026
Merged

sandhose merged 2 commits into
element-hq:developfrom
famedly:tt/fix-presence-stream

Conversation

@FrenchGithubUser

@FrenchGithubUser FrenchGithubUser commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

This is a fix for presence updates silently stalling when a /sync request is cancelled mid-write, causing a stream ID to be leaked into _unfinished_ids and permanently pinning the persisted stream position.

Fixes #19800

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)

@sandhose sandhose left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That is quite an interesting fix, thanks a lot for digging into that!

_load,
db_autocommit=True,
)
except BaseException:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This was a bit weird to me at first, why you would catch BaseException instead of Exception. Turns out, one thing we are interested is catching GeneratorExit, which happens in case a paused coroutine gets garbage collected. Could you just stick a comment why we're catching BaseException and not just Exception?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done in the last commit

Comment on lines +310 to +313
id_gen.get_current_token_for_writer("master"),
7,
"presence stream position is wedged by the cancelled allocation",
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this should be exactly 9, right? As there's the abandoned stream ID + the successful write. Can we assert that instead of just "greater than 7"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

right, done in the last commit

comment on why we catch `BaseException` instead of `Exception`)
@sandhose
sandhose enabled auto-merge (squash) August 13, 2026 12:40
@FrenchGithubUser

Copy link
Copy Markdown
Contributor Author

Thanks a lot for the quick review @sandhose !

@FrenchGithubUser

Copy link
Copy Markdown
Contributor Author

The failing complement test is a flake @sandhose

@sandhose
sandhose merged commit c0357de into element-hq:develop Aug 13, 2026
110 of 114 checks passed
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.

Presence stream stalls intermittently: presence_stream keeps growing while stream_positions(presence_stream, master) stops until restart

3 participants