Skip to content

refactor(Middleware): remove ConnectionSnapshot type - #1261

Merged
ArgoZhang merged 2 commits into
masterfrom
dev-middleware
Oct 28, 2026
Merged

ArgoZhang merged 2 commits into
masterfrom
dev-middleware

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Link issues

fixes #1260

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Remove the obsolete connection snapshot abstraction and make middleware dispatch cancellation responsive.

Bug Fixes:

  • Ensure dispatch operations promptly honor cancellation before invoking subscriptions and while awaiting callbacks.

Enhancements:

  • Remove the obsolete ConnectionSnapshot type from the middleware package.

Build:

  • Update the middleware project configuration to reflect removal of the ConnectionSnapshot source file.

@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The middleware removes the unused ConnectionSnapshot type and updates dispatch execution to honor cancellation before callbacks, while awaiting callbacks, and after callback completion.

Sequence diagram for cancellation-aware middleware dispatch

sequenceDiagram
    participant Caller
    participant DispatchService
    participant Subscription
    participant CallbackTask

    Caller->>DispatchService: DispatchAsync(entry, excludedConnectionId, cancellationToken)
    DispatchService->>DispatchService: cancellationToken.ThrowIfCancellationRequested()
    DispatchService->>Subscription: Callback(entry)
    Subscription-->>DispatchService: CallbackTask
    DispatchService->>CallbackTask: WaitAsync(cancellationToken)
    CallbackTask-->>DispatchService: Completed
    DispatchService->>DispatchService: cancellationToken.ThrowIfCancellationRequested()
    DispatchService-->>Caller: Dispatch completed
Loading

File-Level Changes

Change Details Files
Removes the obsolete connection snapshot abstraction and makes dispatch cancellation responsive throughout subscription processing.
  • Delete the unused ConnectionSnapshot type.
  • Check cancellation before subscription lookup and callback invocation.
  • Await callbacks with cancellation support and recheck cancellation after completion.
  • Continue suppressing dispatch exceptions only when cancellation is active.
src/middleware/BootstrapBlazor.Middleware/ConnectionSnapshot.cs
src/middleware/BootstrapBlazor.Middleware/DefaultDispatchService.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#1260 Remove the ConnectionSnapshot type from the middleware code. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto Bot added the enhancement New feature or request label Oct 28, 2026
@bb-auto bb-auto Bot added this to the v10.0.0 milestone Oct 28, 2026
bb-auto[bot]
bb-auto Bot previously approved these changes Oct 28, 2026

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Auto approved by bb-auto

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Auto approved by bb-auto

@ArgoZhang
ArgoZhang merged commit 6e94dcb into master Oct 28, 2026
3 checks passed
@ArgoZhang
ArgoZhang deleted the dev-middleware branch October 28, 2026 07:45

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/middleware/BootstrapBlazor.Middleware/DefaultDispatchService.cs" line_range="63" />
<code_context>
                 }

-                await callbackTask;
+                await callbackTask.WaitAsync(cancellationToken);
+                cancellationToken.ThrowIfCancellationRequested();
             }
</code_context>
<issue_to_address>
**Callbacks outlive canceled dispatches**

When the token is canceled while a subscription callback is running, `WaitAsync` stops waiting, but `subscription.Callback(entry)` gets no token and keeps running after `DispatchAsync` returns canceled; retries run it concurrently, and later exceptions bypass subscriber-error logging, so callers see duplicate side effects and unlogged failures.

Pass cancellation into callbacks and keep their tasks observed until they finish.
</issue_to_address>

### Comment 2
<location path="src/middleware/BootstrapBlazor.Middleware/DefaultDispatchService.cs" line_range="63-64" />
<code_context>
                 }

-                await callbackTask;
+                await callbackTask.WaitAsync(cancellationToken);
+                cancellationToken.ThrowIfCancellationRequested();
             }
             catch (Exception ex) when (!cancellationToken.IsCancellationRequested)
</code_context>
<issue_to_address>
**Canceled dispatch is delivered twice**

When the SignalR send completes, a local callback is still running, and cancellation leads the caller to retry, `WaitAsync` or the following cancellation check can make `DispatchAsync` return canceled after `clients.SendAsync` has already delivered the entry to the group. A caller that retries the canceled dispatch broadcasts the same entry again, so recipients process a duplicate.

Preserve an unambiguous success result once the broadcast has completed, or make retries idempotent using a dispatch identifier.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

}

await callbackTask;
await callbackTask.WaitAsync(cancellationToken);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Callbacks outlive canceled dispatches

When the token is canceled while a subscription callback is running, WaitAsync stops waiting, but subscription.Callback(entry) gets no token and keeps running after DispatchAsync returns canceled; retries run it concurrently, and later exceptions bypass subscriber-error logging, so callers see duplicate side effects and unlogged failures.

Pass cancellation into callbacks and keep their tasks observed until they finish.

Prompt for AI agents
In `src/middleware/BootstrapBlazor.Middleware/DefaultDispatchService.cs` at line 63:

**Callbacks outlive canceled dispatches**

When the token is canceled while a subscription callback is running, `WaitAsync` stops waiting, but `subscription.Callback(entry)` gets no token and keeps running after `DispatchAsync` returns canceled; retries run it concurrently, and later exceptions bypass subscriber-error logging, so callers see duplicate side effects and unlogged failures.

Pass cancellation into callbacks and keep their tasks observed until they finish.

Comment on lines +63 to +64
await callbackTask.WaitAsync(cancellationToken);
cancellationToken.ThrowIfCancellationRequested();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Canceled dispatch is delivered twice

When the SignalR send completes, a local callback is still running, and cancellation leads the caller to retry, WaitAsync or the following cancellation check can make DispatchAsync return canceled after clients.SendAsync has already delivered the entry to the group. A caller that retries the canceled dispatch broadcasts the same entry again, so recipients process a duplicate.

Preserve an unambiguous success result once the broadcast has completed, or make retries idempotent using a dispatch identifier.

Prompt for AI agents
In `src/middleware/BootstrapBlazor.Middleware/DefaultDispatchService.cs` at lines 63-64:

**Canceled dispatch is delivered twice**

When the SignalR send completes, a local callback is still running, and cancellation leads the caller to retry, `WaitAsync` or the following cancellation check can make `DispatchAsync` return canceled after `clients.SendAsync` has already delivered the entry to the group. A caller that retries the canceled dispatch broadcasts the same entry again, so recipients process a duplicate.

Preserve an unambiguous success result once the broadcast has completed, or make retries idempotent using a dispatch identifier.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(Middleware): remove ConnectionSnapshot type

1 participant