Skip to content

Forward ValueProviderContext in Blazor GatewayOriginReference - #21452

Merged
James Newton-King (JamesNK) merged 2 commits into
mainfrom
aspireagent/fix-21067-blazor-gateway-origin-context
Oct 31, 2026
Merged

James Newton-King (JamesNK) merged 2 commits into
mainfrom
aspireagent/fix-21067-blazor-gateway-origin-context

Conversation

@davidfowl

Copy link
Copy Markdown
Collaborator

Description

Fixes #21067

When a Blazor WebAssembly app is hosted behind a gateway and deployed (for example to Azure Container Apps), the gateway origin used in the client configuration was resolved on the localhost network instead of the network requested by the deployment. As a result, deployment hung forever when localhost was never allocated (the reported Container Apps hang). When localhost was allocated, the localhost URL leaked into the deployed configuration.

Root cause

IValueProvider has a default interface method GetValueAsync(ValueProviderContext, CancellationToken) that falls back to GetValueAsync(CancellationToken), which discards the context. GatewayOriginReference only implemented the context-free overload.

ReferenceExpression.GetValueAsync(context) forwards the NetworkIdentifier to its value providers, but here the network was dropped. The wrapped EndpointReference then waited for a localhost allocation, either forever or until it resolved to a localhost URL.

Fix

GatewayOriginReference now implements the context-aware overload and forwards the context to EndpointReference.GetValueAsync(context, ...), which already supports it. The trailing-slash trimming is unchanged. The context-free path is untouched.

Regression tests

Two new tests in GatewayConfigurationBuilderTests resolve the expression from BuildConfigExpression with a ValueProviderContext that targets a non-localhost network:

  • BuildConfigExpression_ResolvesOriginOnRequestedNetwork_WithoutLocalhostAllocation allocates the endpoint only on the requested network. This matches the reported hang; a 10s WaitAsync guard turns the hang into a failure.
  • BuildConfigExpression_ResolvesOriginOnRequestedNetwork_WhenLocalhostIsAlsoAllocated also allocates localhost and asserts that the requested-network origin is used and no localhost appears.
main (a76b57a) This PR
..._WithoutLocalhostAllocation ❌ TimeoutException (hang) ✅
..._WhenLocalhostIsAlsoAllocated ❌ Assert.Contains() failure: localhost URL substituted ✅

Non-Docker Aspire.Hosting.Blazor.Tests classes, run locally with the fix: 96/97 pass.

  • The one failure is BlazorHostedExtensionsTests.ProxyService_WhenClientDiscoveryFails_SurfacesFailure. It fails identically on unmodified main in my environment, so it's environmental and unrelated.
  • The Docker-based AddBlazorGatewayTests publish tests couldn't run locally, because there was no network access to download the SDK inside containers. CI covers them.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No

🤖 Posted by AspireAgent (AI Agent)

GatewayOriginReference only implemented the context-free GetValueAsync, so
the IValueProvider default interface method dropped the ValueProviderContext.
The gateway origin then resolved on the localhost network during deployment,
which hangs when localhost is never allocated (Container Apps) or emits a
localhost URL.

Fixes #21067

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21452

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21452"

@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot October 30, 2026 12:30
@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 30, 2026
@github-actions

This comment has been minimized.

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.

🟢 Approval recommended

No active review issues are reported for the change preserving the requested network during gateway-origin resolution.

No open issues 🎉

What changed in this PR

Fixes #21067 by preserving the requested network when resolving Blazor gateway origins, preventing deployment hangs or localhost URLs in deployed client configuration.

Changes:

  • Adds a context-aware GatewayOriginReference.GetValueAsync overload that forwards the context while preserving trailing-slash trimming.
  • Adds regression tests for deployment-network resolution both with and without a localhost allocation.
File Description
tests/​Aspire.Hosting.Blazor.Tests/​GatewayConfigurationBuilderTests.cs Tests that generated client configuration uses the requested network.
src/​Aspire.Hosting.Blazor/​GatewayOriginReference.cs Forwards ValueProviderContext to the underlying endpoint.

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@davidfowl
David Fowler (davidfowl) marked this pull request as ready for review October 30, 2026 13:45
# Conflicts:
#	tests/Aspire.Hosting.Blazor.Tests/GatewayConfigurationBuilderTests.cs
@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

3 / 100 PR test projects · 3 PR jobs, from 2 changed files.

Selected PR test projects (3 / 100)

Aspire.Cli.EndToEnd.Tests, Aspire.Hosting.Blazor.Tests, Aspire.Playground.Tests

Selected PR jobs (3)

extension-e2e, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

🔧 src/Aspire.Hosting.Blazor/GatewayOriginReference.cs (changed source)
→ 1 directly: Aspire.Hosting.Blazor.Tests
→ 1 via the project graph: Aspire.Playground.Tests

📦 affected project Aspire.Hosting.Blazor
→ 1 test: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Hosting.Blazor.Tests/GatewayConfigurationBuilderTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Blazor.Tests

Job reasons

Job Triggered by
extension-e2e • src/Aspire.Hosting.Blazor/GatewayOriginReference.cs
• affected project Aspire.Hosting.Blazor
polyglot affected project Aspire.Hosting.Blazor
typescript-api-compat affected project Aspire.Hosting.Blazor

Selection computed for commit e3ce2cb.

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.

🟢 Approval recommended

No active review issues are recorded for the change preserving the requested network during Blazor gateway origin resolution.

No open issues 🎉

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

Copy link
Copy Markdown
Collaborator Author

Merged main into this branch to resolve the conflict in the using/#pragma header of GatewayConfigurationBuilderTests.cs. The fix is unchanged. All 22 GatewayConfigurationBuilderTests pass locally, including both new requested-network regression tests.

On the new head, two Windows VS Code extension E2E jobs failed (resource-debug-tools and coordinated-build) with "The hosted runner lost communication with the server" (run). That's a runner infrastructure problem and unrelated to this Blazor gateway change. The failed jobs are being rerun once.

🤖 Posted by AspireAgent (AI Agent)

@JamesNK
James Newton-King (JamesNK) merged commit d77dac9 into main Oct 31, 2026
413 of 417 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.0 milestone Oct 31, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

✅ No documentation update needed.

docs_optional → bug_fix_restores_documented_behavior. No signals triggered (signal_count == 0). The PR forwards ValueProviderContext in the Blazor GatewayOriginReference so the gateway origin resolves on the requested network during deployment. It fixes an internal hang and a localhost leak, and adds no new public surface, options or strings.

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

Labels

needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blazor: GatewayOriginReference drops ValueProviderContext, causing Container Apps deployment to hang

3 participants