Skip to content

fix: presence stream stalling intermittently - #281

Closed
FrenchGithubUser wants to merge 1 commit into
masterfrom
tt/fix-presence-stream
Closed

FrenchGithubUser wants to merge 1 commit into
masterfrom
tt/fix-presence-stream

Conversation

@FrenchGithubUser

Copy link
Copy Markdown
Member

@FrenchGithubUser FrenchGithubUser changed the title Tt/fix presence stream fix: presence stream stalling intermittently Aug 13, 2026
@FrenchGithubUser
FrenchGithubUser marked this pull request as ready for review August 13, 2026 12:18
@FrenchGithubUser
FrenchGithubUser requested a review from a team as a code owner August 13, 2026 12:18
@cursor

cursor Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches core MultiWriterIdGenerator async entry used by presence and other streams; logic is narrow (cleanup on failed/cancelled __aenter__) but incorrect handling could advance tokens without persisted rows.

Overview
Fixes intermittent presence stream stalls where clients stop receiving presence updates until Synapse restarts.

When a cancellable /sync request is aborted while MultiWriterIdGenerator.get_next() is still in __aenter__, the DB sequence may already have allocated a stream ID and left it in _unfinished_ids, but Python never runs __aexit__ because __aenter__ did not return. That leaked ID pins the persisted stream position (including presence).

The change records allocated IDs on the context manager inside the load transaction, and on any exception from runInteraction (including CancelledError) calls _mark_ids_as_finished and notifies replication—the same cleanup as the failure path in __aexit__, without advancing stream_positions on an incomplete write.

A regression test simulates cancelled /sync during presence-like allocation and asserts a later write can advance the token past the wedged position.

Reviewed by Cursor Bugbot for commit d6706b8. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov

codecov Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.73%. Comparing base (013821e) to head (d6706b8).

Files with missing lines Patch % Lines
synapse/storage/util/id_generators.py 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #281      +/-   ##
==========================================
- Coverage   80.73%   80.73%   -0.01%     
==========================================
  Files         503      503              
  Lines       72286    72296      +10     
  Branches    10872    10873       +1     
==========================================
+ Hits        58363    58369       +6     
- Misses      10658    10660       +2     
- Partials     3265     3267       +2     
Files with missing lines Coverage Δ
synapse/storage/util/id_generators.py 90.72% <90.90%> (-0.03%) ⬇️

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 013821e...d6706b8. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@FrenchGithubUser

Copy link
Copy Markdown
Member Author

upstream PR got merged earlier, we'll cherry pick the commit in a follow up pr

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