Passing an invalid ReferenceExpression as an environment variable propagates a silent failure
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
Passing an invalid ReferenceExpression to a project resource (invalid: trying to access `Property(EndpointProperty.Url)` on a connection string that isn't a well-formed URI) has two consequences:
- The dependent resource fails to start, which is reasonable given that it's been given configuration that doesn't resolve properly, but doesn't log anything explaining why
- When the dependent resource is a ProjectResource, the 'Rebuild' command implicitly attempts to stop this resource, but it appears that since the resource never started, DCP doesn't recognise that it exists, and logs a stack trace
### Expected Behavior
- The incorrect ReferenceExpression is logged in the console for the failed resource start
- Rebuilding a failed resource start recognises the edge case that DCP can't stop a project that never existed
### Steps To Reproduce
Repro is at: https://github.com/TWolversonReply/RefExprRepro
Summary:
Add an AzureCosmosDb resource
Add any other resource, such as a project or a container - the example I first discovered this with was a local checkout of https://github.com/AzureCosmosDB/MCPToolKit. I don't believe what the consuming resource is matters at all - although it needs to be a project to expose the secondary DCP issue with Rebuild
Pass through .WithEnvironment a ReferenceExpression that decomposes the https endpoint of the CosmosDb resource:
`.WithEnvironment("COSMOS_ENDPOINT", ReferenceExpression.Create($"{cosmos.GetEndpoint("https").Property(EndpointProperty.Url)}"))`
### Exceptions (if any)
When trying to rebuild a failed project:
```
Error executing command 'rebuild'.
k8s.Autorest.HttpOperationException: Operation returned an invalid status code 'NotFound', response body {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"executables.usvc-dev.developer.microsoft.com \"web-pfsjfyea\" not found","reason":"NotFound","details":{"name":"web-pfsjfyea","group":"usvc-dev.developer.microsoft.com","kind":"executables"},"code":404}
at k8s.Kubernetes.SendRequestRaw(String requestContent, HttpRequestMessage httpRequest, CancellationToken cancellationToken)
at k8s.AbstractKubernetes.ICustomObjectsOperations_PatchClusterCustomObjectWithHttpMessagesAsync[T](Object body, String group, String version, String plural, String name, String dryRun, String fieldManager, String fieldValidation, Nullable`1 force, IReadOnlyDictionary`2 customHeaders, CancellationToken cancellationToken)
at k8s.AbstractKubernetes.k8s.ICustomObjectsOperations.PatchClusterCustomObjectWithHttpMessagesAsync(Object body, String group, String version, String plural, String name, String dryRun, String fieldManager, String fieldValidation, Nullable`1 force, IReadOnlyDictionary`2 customHeaders, CancellationToken cancellationToken)
at Aspire.Hosting.Dcp.KubernetesService.<>c__DisplayClass18_0`1.<b__0>d.MoveNext() in /_/src/Aspire.Hosting/Dcp/KubernetesService.cs:line 170
--- End of stack trace from previous location ---
at Aspire.Hosting.Dcp.KubernetesService.<>c__DisplayClass28_0`1.<b__0>d.MoveNext() in /_/src/Aspire.Hosting/Dcp/KubernetesService.cs:line 483
--- End of stack trace from previous location ---
at Polly.ResiliencePipeline.<>c__10`1.<b__10_0>d.MoveNext()
--- End of stack trace from previous location ---
at Polly.Outcome`1.GetResultOrRethrow()
at Polly.ResiliencePipeline.ExecuteAsync[TResult](Func`2 callback, CancellationToken cancellationToken)
at Aspire.Hosting.Dcp.KubernetesService.ExecuteWithRetry[TResult](DcpApiOperationType operationType, String resourceType, Func`2 operation, Func`2 isRetryable, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/Dcp/KubernetesService.cs:line 480
at Aspire.Hosting.Dcp.DcpExecutor.<>c__DisplayClass88_0.<b__0>d.MoveNext() in /_/src/Aspire.Hosting/Dcp/DcpExecutor.cs:line 2537
--- End of stack trace from previous location ---
at Polly.ResiliencePipeline.<>c__9`2.<b__9_0>d.MoveNext()
--- End of stack trace from previous location ---
at Polly.Outcome`1.GetResultOrRethrow()
at Polly.ResiliencePipeline.ExecuteAsync[TResult,TState](Func`3 callback, TState state, CancellationToken cancellationToken)
at Aspire.Hosting.Dcp.DcpExecutor.StopResourceAsync(IResourceReference resourceReference, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/Dcp/DcpExecutor.cs:line 2515
at Aspire.Hosting.Orchestrator.ApplicationOrchestrator.StopResourceAsync(String resourceName, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/Orchestrator/ApplicationOrchestrator.cs:line 593
at Aspire.Hosting.ApplicationModel.CommandsConfigurationExtensions.ExecuteRebuildAsync(ExecuteCommandContext context, ProjectResource projectResource) in /_/src/Aspire.Hosting/ApplicationModel/CommandsConfigurationExtensions.cs:line 216
at Aspire.Hosting.ApplicationModel.ResourceCommandService.ExecuteCommandCoreAsync(String resourceId, IResource resource, String commandName, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/ApplicationModel/ResourceCommandService.cs:line 161
```
### Aspire doctor output
Aspire Environment Check
========================
.NET SDK
✔ .NET 10.0.104 installed (x64)
Container Runtime
⚠ Docker Engine detected. Aspire's container tunnel is required to allow containers to reach applications running on the host
Set environment variable: ASPIRE_ENABLE_CONTAINER_TUNNEL=true
See: https://aka.ms/aspire-prerequisites#docker-engine
Environment
✔ HTTPS development certificate is trusted
⚠ HTTPS development certificate has an older version (v4)
Run 'aspire certs clean' to remove all certificates, then run 'aspire certs trust' to create and trust a new one.
See: https://aka.ms/aspire-prerequisites#dev-certs
Details:
Older certificate versions (< v4) may not support all certificate trust scenarios.
Summary: 2 passed, 2 warnings, 0 failed
For detailed prerequisites: https://aka.ms/aspire-prerequisites
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.