Skip to content

Stop circuit breakers keeping the ExecutionContext of the code that built them alive - #68

Open
iancooper wants to merge 1 commit into
mainfrom
port/813d10a6-suppress-executioncontext-flow
Open

iancooper wants to merge 1 commit into
mainfrom
port/813d10a6-suppress-executioncontext-flow

Conversation

@iancooper

Copy link
Copy Markdown
Member

Port of App-vNext/Polly@813d10a6 (App-vNext/Polly#3284, which fixes App-vNext/Polly#3275). Upstream sync #3, tracked in #66.

Problem

ScheduledTaskExecutor's constructor starts its processing loop with Task.Run, which flows the creator's ExecutionContext into a loop that lives as long as the circuit breaker. The first caller's AsyncLocal values are therefore never collected. Pipelines held in a registry, such as those used by Microsoft.Extensions.Http.Resilience, live for the whole app, so ambient state such as a Blazor Server circuit leaks.

Change

  • ScheduledTaskExecutor's constructor wraps the Task.Run in using (ExecutionContext.SuppressFlow()), matching upstream line for line, comment included.
  • Upstream's regression test is ported as Constructor_AmbientExecutionContext_IsNotCaptured (renamed to Member_Scenario_Outcome, with Arrange/Act/Assert comments added).

The test failed before the fix (reference.IsAlive should be False but was True) and passes after it.

Verification

  • Paramore.Fences.Core.Tests: 782/782 pass in Release on net10.0, net9.0 and net8.0.
  • Paramore.Fences.Core builds analyser-clean for all TFMs.
  • No public API change (ScheduledTaskExecutor is internal). No dependency changes.

Refs #66

🤖 Generated with Claude Code

https://claude.ai/code/session_01U6RM4Rd2HejEcaWDY3qovL

…e circuit breaker's scheduled task loop

ScheduledTaskExecutor's constructor started its processing loop with
Task.Run, which captured the creator's ExecutionContext. The loop lives as
long as the pipeline, so the first caller's AsyncLocal values were never
collected. Wrap the Task.Run in ExecutionContext.SuppressFlow().

Upstream: App-vNext/Polly#3284 (fixes App-vNext/Polly#3275).
Refs #66

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U6RM4Rd2HejEcaWDY3qovL

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.

Circuit breaker keeps the ExecutionContext of whoever builds the pipeline alive for the pipeline's lifetime

1 participant