Skip to content

Fix AllocatedEndpoint API#14459

Merged
karolz-ms merged 13 commits intorelease/13.2from
dev/karolz/allocated-endpoint
Feb 13, 2026
Merged

Fix AllocatedEndpoint API#14459
karolz-ms merged 13 commits intorelease/13.2from
dev/karolz/allocated-endpoint

Conversation

@karolz-ms
Copy link
Member

While working on local app run and container tunnel improvements, I discovered to my dismay that the AllocatedEndpoint management API (specifically, NetworkEndpointSnapshotList.TryAdd() is quite broken. It will not properly reuse existing snapshots. The result is that it is not possible to properly wait for an AllocatedEndpoint to appear in the system.

The fix proposed here is to add a better API (namely upsert + asynchronous, cancellable get) and obsolete the old API.

@karolz-ms karolz-ms added this to the 13.2 milestone Feb 12, 2026
@karolz-ms karolz-ms self-assigned this Feb 12, 2026
Copilot AI review requested due to automatic review settings February 12, 2026 02:30
@github-actions
Copy link
Contributor

github-actions bot commented Feb 12, 2026

🚀 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/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14459

Or

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

Copy link
Contributor

Copilot AI left a comment

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 fixes broken allocated-endpoint snapshot reuse by introducing a new upsert + async retrieval API on NetworkEndpointSnapshotList, and updates existing call sites/tests to use the new API while obsoleting the old TryAdd() method.

Changes:

  • Add AddOrUpdateAllocatedEndpoint(...) and GetAllocatedEndpointAsync(...); mark TryAdd(...) obsolete.
  • Update EndpointReferenceExpression resolution to await allocated endpoints via the new async API.
  • Refactor DCP executor logic and multiple tests to use the new upsert API instead of manually creating ValueSnapshot<AllocatedEndpoint> instances.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/Aspire.Hosting.Tests/WithEnvironmentTests.cs Switches tests from TryAdd(ValueSnapshot) to AddOrUpdateAllocatedEndpoint(...).
tests/Aspire.Hosting.Tests/ExpressionResolverTests.cs Updates container-network allocated endpoint setup to use the new API.
tests/Aspire.Hosting.Tests/EndpointReferenceTests.cs Updates allocated endpoint setup to use the new API in property-resolution tests.
tests/Aspire.Hosting.Redis.Tests/AddRedisTests.cs Replaces snapshot construction + TryAdd with AddOrUpdateAllocatedEndpoint(...).
tests/Aspire.Hosting.Qdrant.Tests/AddQdrantTests.cs Replaces snapshot construction + TryAdd with AddOrUpdateAllocatedEndpoint(...).
tests/Aspire.Hosting.PostgreSQL.Tests/PostgresMcpBuilderTests.cs Replaces snapshot construction + TryAdd with AddOrUpdateAllocatedEndpoint(...).
tests/Aspire.Hosting.Milvus.Tests/AddMilvusTests.cs Replaces snapshot construction + TryAdd with AddOrUpdateAllocatedEndpoint(...).
tests/Aspire.Hosting.Containers.Tests/ContainerResourceTests.cs Replaces snapshot construction + TryAdd with AddOrUpdateAllocatedEndpoint(...).
tests/Aspire.Hosting.Azure.Tests/AzurePostgresExtensionsTests.cs Replaces snapshot construction + TryAdd with AddOrUpdateAllocatedEndpoint(...).
src/Aspire.Hosting/Dcp/DcpExecutor.cs Uses AddOrUpdateAllocatedEndpoint(...) when populating allocated endpoints for container networks/tunnels.
src/Aspire.Hosting/ApplicationModel/EndpointReference.cs Resolves allocated endpoints via GetAllocatedEndpointAsync(...) instead of TryAdd/manual snapshot logic.
src/Aspire.Hosting/ApplicationModel/EndpointAnnotation.cs Introduces the new API and obsoletes TryAdd(...); constructor still wires default snapshot.

Copy link
Contributor

Copilot AI commented Feb 12, 2026

@karolz-ms I've opened a new pull request, #14462, to work on those changes. Once the pull request is ready, I'll request review from you.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Feb 12, 2026

🎬 CLI E2E Test Recordings

The following terminal recordings are available for commit f3713e1:

Test Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
CreateAndDeployToDockerCompose ▶️ View Recording
CreateAndDeployToDockerComposeInteractive ▶️ View Recording
CreateAndPublishToKubernetes ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateEmptyAppHostProject ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateStartWaitAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
ResourcesCommandShowsRunningResources ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording

📹 Recordings uploaded automatically from CI run #22005273576

Copy link
Contributor

@afscrome afscrome left a comment

Choose a reason for hiding this comment

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

I'll try and play around with this more when I'm home later, but one small piece of feedback that caught me out with my previous endpoint refactor PR.

@karolz-ms
Copy link
Member Author

karolz-ms commented Feb 13, 2026

DO NOT MERGE till #14459 (comment) is addressed

UPDATE: done.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

We should consider what we should do with DevTunnels, as we can't make the API internal with DevTunnels using it.

Copy link
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

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

This LGTM other than the one comment left. One other thing to think about (no need to block this PR for it) is to apart from introducing the obsoletes, also introducing a quick code-fixer and analyzer so people updating their packages can super easily just apply the code fixer to fix their apphosts. @DamianEdwards can correct me, but I think we have done htat in other places.

@DamianEdwards
Copy link
Member

@joperezr RE code-fixers we only have analyzers right now, no code-fixers.

@karolz-ms karolz-ms enabled auto-merge (squash) February 13, 2026 22:39
@karolz-ms karolz-ms merged commit d193893 into release/13.2 Feb 13, 2026
676 of 679 checks passed
@karolz-ms karolz-ms deleted the dev/karolz/allocated-endpoint branch February 13, 2026 23:10
@dotnet-policy-service dotnet-policy-service bot modified the milestone: 13.2 Feb 13, 2026
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.

8 participants