Skip to content

fix(streaming): remove defunct stream publishers - #10532

Merged
ReubenBond merged 28 commits into
dotnet:mainfrom
ReubenBond:rb-fix-sms-stream-restart
Sep 16, 2026
Merged

ReubenBond merged 28 commits into
dotnet:mainfrom
ReubenBond:rb-fix-sms-stream-restart

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

Persistent stream pulling agents are system targets whose identities include their silo address and generation. Pub/sub state survives a cluster restart, while shutdown-time publisher unregistration is best-effort. When unregistration races silo teardown, the persisted publisher remains and the replacement pulling agent registers under a new identity, producing the duplicate publisher observed in #10503, #10702, #10822, and #11033.

Producer registration now validates persisted system-target publishers against cluster membership before adding the replacement. Publishers on terminating or dead silo generations are removed and the updated rendezvous state is persisted before removal metrics are emitted. Ordinary producers retain their existing registration path.

Legacy and future-version participants require a fresh source-of-truth membership observation. Each refresh operation retains the newest status observed for its participating silo generations, so correctness is independent of bounded-cache eviction and an older refresh cannot overwrite a newer dead classification. Registrations carry the membership version which observed the producer silo, and stale registrations are rejected so an old pulling agent cannot restore itself after cleanup.

Recreated membership storage can reuse a version recorded in durable pub/sub state. Absent publishers at that equal-version boundary also receive fresh source-of-truth validation. This resolves the previous silo generation and allows the healthy replacement to register even when its endpoint changes and cluster membership remains stable.

Legacy persisted publisher state retains its default membership-version sentinel. Pinned RPC aliases preserve rolling compatibility for the expanded cancellable RegisterProducer contract across generated callers and targets.

Fixes #10503
Fixes #10702
Fixes #10822
Fixes #11033

Copilot AI lite review requested due to automatic review settings August 12, 2026 02:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses duplicate stream publishers in the pub/sub registry after cluster restarts by removing defunct system-target publishers (e.g., persistent stream pulling agents) before registering a replacement producer, plus adding a regression test to validate the behavior.

Changes:

  • Inject IClusterMembershipService into PubSubRendezvousGrain and remove terminating/dead system-target producers prior to RegisterProducer.
  • Add a regression test which registers a producer from a predecessor silo generation and verifies that registering the replacement leaves a single producer.
Show a summary per file
File Description
src/Orleans.Streaming/PubSub/PubSubRendezvousGrain.cs Removes terminating/dead system-target producers before registering a new producer to prevent duplicate persisted publishers after restarts.
test/Orleans.Streaming.Tests/StreamingTests/PubSubRendezvousGrainTests.cs Adds a regression test ensuring a replacement pulling agent registration results in exactly one publisher.

Review details

Tip

Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings August 12, 2026 02:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings August 12, 2026 19:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings August 12, 2026 20:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings August 12, 2026 21:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

Suppressed comments (1)

src/Orleans.Streaming/PubSub/PubSubRendezvousGrain.cs:134

  • RegisterProducer now calls RemoveDefunctSystemTargetProducers() for every producer registration. That method scans all existing producers and can trigger a membership-source refresh, which adds avoidable overhead for normal (non-pulling-agent) producers. Since the duplicate-publisher scenario is specific to stream pulling agents (system targets), consider gating this cleanup to only run when the registering producer is a pulling agent system target.
                await RemoveDefunctSystemTargetProducers();
  • Files reviewed: 11/11 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings August 13, 2026 14:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 11/11 changed files
  • Comments generated: 1
  • Review effort level: Lite

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

Suppressed comments (1)

test/Orleans.Streaming.Tests/StreamingTests/PubSubRendezvousGrainTests.cs:131

  • replacementProducer is built using rendezvousSilo, which doesn’t exercise the restart/replacement identity scenario the test name describes. To validate that a producer from the restarted silo’s new address replaces the persisted producer from the old generation, create the replacement producer using replacementSilo.SiloAddress instead.
            var replacementProducer = SystemTargetGrainId.Create(
                Constants.StreamPullingAgentType,
                rendezvousSilo,
                "ProviderName_1_test-queue").GrainId;
  • Files reviewed: 11/11 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings August 15, 2026 09:12
@ReubenBond
ReubenBond force-pushed the rb-fix-sms-stream-restart branch from d74e302 to 1935a04 Compare August 15, 2026 09:12
ReubenBond and others added 22 commits September 13, 2026 08:05
Add an explicit IMembershipManager source-freshness operation instead of overloading Refresh semantics. Table-based membership guarantees progress with an independent full read, while implementations may also satisfy the fence using writes which publish complete views.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 1abf096e-7d27-435b-9339-a78329f6fb12
Fold source freshness fencing into IMembershipManager.Refresh using an explicit requireFresh option while preserving existing coalesced refresh behavior by default.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 1abf096e-7d27-435b-9339-a78329f6fb12
Prevent delayed pulling-agent registrations from recreating stale pub/sub entries after a replacement publisher has registered. Reject the registration with a retryable failure so transient membership convergence cannot silently drop an active publisher.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 8f04121e-7bad-4fe4-9746-4856285ebca8
Reject incoming system-target publishers when membership validation is indeterminate so a failed source refresh cannot recreate a stale publisher. Existing unknown publishers remain retained until their status can be confirmed.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 8f04121e-7bad-4fe4-9746-4856285ebca8
Make distinct silo addresses an input invariant and propagate cancellation through the fresh membership refresh.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b80076ce-da56-4d4f-8419-e30849633d6e
Flow the registering silo's observed membership version through an additive pub/sub RPC and persisted publisher state so causally newer membership snapshots reject defunct publishers. Treat the default membership version as legacy state during rolling upgrades.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b80076ce-da56-4d4f-8419-e30849633d6e
Make the default membership version's persisted-state compatibility role explicit and align registration rejection diagnostics with runtime behavior.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b80076ce-da56-4d4f-8419-e30849633d6e
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b80076ce-da56-4d4f-8419-e30849633d6e
@ReubenBond
ReubenBond force-pushed the rb-fix-sms-stream-restart branch from bcc3236 to c3fcfd3 Compare September 13, 2026 15:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

2 participants