Fix hang when trying to deploy single compute resource#12797
Conversation
Add PipelineConfigurationAnnotation to AzureBicepResource to establish dependencies between Azure resources based on parameter references. This fixes hangs when deploying subsets of resources (e.g., aspire do deploy-<resource>). Changes: - Added PipelineConfigurationAnnotation in AzureBicepResource constructor - Walks parameters using IValueWithReferences to find Azure resource dependencies - Makes provision steps depend on referenced Azure resources' provision steps - Added test to verify dependency graph via diagnostics output Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12797Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12797" |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a deployment hang issue that occurs when Azure Bicep resources depend on other Azure resources (e.g., when a compute resource references a KeyVault secret). The fix establishes proper pipeline dependencies between Azure resources by detecting resource references through the IValueWithReferences interface and ensuring provision steps execute in the correct order.
Key Changes
- Added pipeline configuration logic to
AzureBicepResourceconstructor that automatically detects and establishes dependencies on referenced Azure resources - Implemented
ProcessAzureReferenceshelper method to recursively extract Azure resource references from parameter values - Added comprehensive test that verifies the fix prevents deployment hangs and includes snapshot verification of the dependency graph
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/Aspire.Hosting.Azure/AzureBicepResource.cs |
Added PipelineConfigurationAnnotation to detect Azure resource references in parameters and establish provision step dependencies; added ProcessAzureReferences helper methods |
tests/Aspire.Hosting.Azure.Tests/AzureDeployerTests.cs |
Added parameterized test covering both deploy and diagnostics modes to verify deployment completes without hanging when resources have dependencies |
tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureDeployerTests.DeployAsync_WithAzureResourceDependencies_DoesNotHang_step=diagnostics.verified.txt |
Snapshot file capturing expected dependency graph diagnostic output showing correct execution order and dependencies |
| /// <summary> | ||
| /// Processes a value to extract Azure resource references and adds them to the collection. | ||
| /// Uses IValueWithReferences to recursively walk the reference graph. | ||
| /// </summary> | ||
| private static void ProcessAzureReferences(HashSet<IAzureResource> azureReferences, object? value) |
There was a problem hiding this comment.
The XML documentation for ProcessAzureReferences is missing <param> tags for the parameters. According to the coding guidelines, all parameters should be documented with <param> tags. Add: <param name="azureReferences">The collection to populate with discovered Azure resource references.</param> and <param name="value">The value to process for Azure resource references.</param>
| ProcessAzureReferences(azureReferences, value, []); | ||
| } | ||
|
|
||
| private static void ProcessAzureReferences(HashSet<IAzureResource> azureReferences, object? value, HashSet<object> visited) |
There was a problem hiding this comment.
This private overload is missing XML documentation. Since it's a private method, it should have a brief <summary> tag explaining its purpose and parameters. The public coding guidelines indicate even internal/private APIs should have minimal documentation with brief <summary> tags.
|
/backport to release/13.0 |
|
Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/19164786381 |
- Add PipelineConfigurationAnnotation to AzureBicepResource to set up dependencies - Add ProcessAzureReferences helper methods to find Azure resource dependencies - Add test DeployAsync_WithAzureResourceDependencies_DoesNotHang (adapted for release/13.0) - Update snapshot for DeployAsync_WithMultipleComputeEnvironments_Works - Tests adjusted to work without IContainerRuntime.LoginToRegistryAsync (not in release/13.0) Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
| // Force evaluation of the Bicep template to ensure parameters are expanded | ||
| _ = GetBicepTemplateString(); |
There was a problem hiding this comment.
We should make a better way to do this at some point. Initialize() or something.
…#12800) * Initial plan * Backport PR #12797 fix for deployment hang to release/13.0 - Add PipelineConfigurationAnnotation to AzureBicepResource to set up dependencies - Add ProcessAzureReferences helper methods to find Azure resource dependencies - Add test DeployAsync_WithAzureResourceDependencies_DoesNotHang (adapted for release/13.0) - Update snapshot for DeployAsync_WithMultipleComputeEnvironments_Works - Tests adjusted to work without IContainerRuntime.LoginToRegistryAsync (not in release/13.0) Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Fix hang when deploying single Azure resource to App Service
Problem: When deploying a subset of Azure resources using commands like
aspire do deploy-ai-agent, the deployment hangs because dependencies between Bicep resources are not expressed in the pipeline.Root Cause: Azure Bicep resources didn't declare dependencies on other Azure resources referenced in their parameters, causing deployment deadlocks when running subsets of the dependency graph.
Solution:
Key Changes:
AzureBicepResource.cs: Added PipelineConfigurationAnnotation that:
GetBicepTemplateString()to materialize parametersProcessAzureReferences()to recursively find IAzureResource dependencies via IValueWithReferencescontext.GetSteps()Test: Added
DeployAsync_WithAzureResourceDependencies_DoesNotHangtest that:Verification: The diagnostic output snapshot shows correct dependency:
provision-api-websitenow depends onprovision-kv(line 101 in snapshot).Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.