Repository navigation
Fall back to default container host name when DCP reports an empty one - #21432
Karol Zadora-Przylecki (karolz-ms) merged 2 commits into
Conversation
When the container runtime CLI is slow, 'dcp info' times out internally and reports hostName as an empty string. ContainerHostName only fell back on null, so containers got OTEL endpoints like 'http://:4317'. Treat empty as missing and use ContainerHostName in all consumers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21432Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21432" |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 Changes recommended
The tests introduce a private DCP fake and service-provider wrapper that duplicate shared test helpers, which should be extended to accept configurable DcpInfo and reused instead.
1 open issue
What changed in this PR
This PR fixes malformed container endpoint URLs when DCP reports an empty host name after a runtime query timeout. It applies a shared runtime-specific fallback across Aspire hosting consumers.
Changes:
- Treat null or empty host names as missing while preserving custom host names.
- Use the shared fallback in container execution and endpoint provisioning.
- Add regression tests for DCP metadata and OTLP endpoint resolution.
| File | Description |
|---|---|
tests/Aspire.Hosting.Tests/ExpressionResolverTests.cs |
Verifies OTLP endpoint resolution with an empty DCP host name. |
tests/Aspire.Hosting.Tests/Dcp/DcpDependencyCheckTests.cs |
Tests fallback and custom host names from deserialized metadata. |
src/Aspire.Hosting/Dcp/IDcpDependencyCheckService.cs |
Applies runtime-specific defaults to empty host names. |
src/Aspire.Hosting/Dcp/DcpExecutor.cs |
Uses the shared container host-name fallback. |
src/Aspire.Hosting/Dcp/ContainerNetworkEndpointProvisioner.cs |
Uses the shared fallback during endpoint provisioning. |
Review effort: Balanced
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Tests selector52 / 100 PR test projects · 4 PR jobs, from 7 changed files. Selected PR test projects (52 / 100)
Selected PR jobs (4)
How these were chosen — grouped by what changed
🧪 show 34
🔧 🧪 📦 affected project 📦 affected project 🧪 Job reasons
Selection computed for commit |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
d85136b
into
main
|
✅ No documentation update needed. Step 5 branch: docs_optional → bug_fix_restores_documented_behavior. No signals triggered (signal_count 0). The PR makes |
) ## What failed `Aspire.Hosting.Java.Tests.AddJavaContainerTests.AddJavaContainer_ExportsTelemetryToAspire` failed in `Hosting.Java (windows-latest)` on attempt 1 with: ``` System.AggregateException : One or more errors occurred while resolving resource configuration. (Application orchestrator dependency check returned an error: The operation has timed out. ... dcp.info.os-executor Context expired, stopping process... {"Command": "C:\\Windows\\system32\\docker.exe", "Args": ["--version"]} at Aspire.Hosting.Dcp.DcpDependencyCheck.GetDcpInfoAsync(...) at Aspire.Hosting.ApplicationModel.HostUrl...GetValueAsync(...) ``` Runs: [41873115695](https://github.com/microsoft/aspire/actions/runs/41873115695) (main, 11-04) and [42181390567](https://github.com/microsoft/aspire/actions/runs/42181390567) (PR, 11-06). This is rank 5 in the unowned-flakes list on #21600. ## Why The test builds a run-mode app and resolves the container's environment. `OTEL_EXPORTER_OTLP_ENDPOINT` is a `HostUrl`, and in run mode `HostUrl` asks `IDcpDependencyCheckService` for the container host name. The real service runs `dcp info` under the 25s `DcpOptions.DependencyCheckTimeout`. On busy Windows runners, DCP's `docker --version` probe inside `dcp info` sometimes takes longer than that (the shared infra cause tracked in #21771), so the test fails before it reaches its assertion. `WithJvmArgs_AppliesToAContainerToo` in the same class goes through the same path. The test only needs a container host name from DCP. It doesn't need DCP itself. Its old assertion also compared the env var against a second call to that same live service, so it couldn't catch `HostUrl` ignoring the host name DCP reports. ## How it's fixed Test-only change. Both tests register a deterministic `IDcpDependencyCheckService` (the existing `TestDcpDependencyCheckService` from `Aspire.Hosting.TestUtilities`, which now grants `InternalsVisibleTo` to `Aspire.Hosting.Java.Tests` like the Go and Dotnet test projects). `AddJavaContainer_ExportsTelemetryToAspire` now reports `host.wslc.internal` (the runtime-specific case from #21244) and asserts the exact `http://host.wslc.internal:4317`. The test still builds the app and goes through the real `HostUrl` and `DcpOptions` path. No timeouts, retries or assertions were relaxed. **Related:** #21316 (closed without merging) targeted an earlier failure of this same test, a different root cause: DCP reported an empty container host name, which produced `http://:4317`. #21432 fixed that cause on main on 10-30. This PR fixes the remaining `dcp info` timeout signature, which neither PR covers. ## Confidence - **Before** (main `2f471dc6`, `DcpPublisher__CliPath` pointing at a fake `dcp` whose `info` hangs for 60s): **3/3 runs fail**. Both tests fail after about 30s with the same `Application orchestrator dependency check returned an error: The operation has timed out` message as CI. - **After**, same hanging `dcp`: **10/10 runs pass** (14/14 tests, about 1s). - **After**, real DCP 0.27.3 (Linux x64): **20/20 runs pass**. - **Regression check:** if `HostUrl` is changed to ignore DCP's host name (always `host.docker.internal`), the new test fails with `Expected: "http://host.wslc.internal:4317"`, `Actual: "http://host.docker.internal:4317"`. The old assertion would still pass on any runner where DCP reports `host.docker.internal`. - **Main uncertainty:** the underlying Windows `docker --version` slowness isn't fixed here. It can still affect tests that actually start DCP, and #21771 tracks it. **How we stop this recurring:** unit tests that only need a value from DCP (such as the container host name) should register a deterministic `IDcpDependencyCheckService` instead of running the real `dcp info`. ## Failure stats (14d, attempt 1) Source: a scan of every CI (`ci.yml`) run created 10-09 → 11-08 13:00Z, using attempt-1 `Hosting.Java` jobs and their logs. - **Exact test / signature:** `Aspire.Hosting.Java.Tests.AddJavaContainerTests.AddJavaContainer_ExportsTelemetryToAspire` failing with `Application orchestrator dependency check returned an error: The operation has timed out ... docker.exe --version` (Windows). - **Main:** 1/161 runs where the `Hosting.Java` job ran (0.6%). **PR:** 1/471 (0.2%). Including the sibling `WithJvmArgs_AppliesToAContainerToo`, which has the same signature and is fixed here, PR is 2/471 (0.4%). - **Rerun-pass:** 1 of 1 rerun (the other hits were not re-run). - **Last hit:** 11-06 07:31Z. Runs: [42181390567](https://github.com/microsoft/aspire/actions/runs/42181390567) (PR), [42134705233](https://github.com/microsoft/aspire/actions/runs/42134705233) (PR, sibling test), [41873115695](https://github.com/microsoft/aspire/actions/runs/41873115695) (main). - **30d main hits (this signature):** 1/280. The other 30d failures of this test were `Strings differ` (WSLc and empty host name), fixed by #21254 and #21432. None has appeared since #21432 merged on 10-30 15:51Z. One more hit, [41194713391](https://github.com/microsoft/aspire/actions/runs/41194713391) (DCP `CliPath` validation on both OSes), is branch-caused and excluded. - **Local:** before the fix, 0/3 passed with a hanging `dcp info`. After the fix, 10/10 passed with a hanging `dcp info` and 20/20 with real DCP. The mutation check fails as expected. - **PR CI:** CI run [42491774241](https://github.com/microsoft/aspire/actions/runs/42491774241) passed on attempt 1, including `Hosting.Java` on Windows and Ubuntu. - **Verdict: MODERATE.** The hit count is low (3 including the sibling), but one hit is on main, the CI error reproduces exactly in a deterministic local test, and the same probe timeout hits other tests (#21771). ## Checklist - Is this feature complete? - [x] Yes. Ready to ship. - [ ] No. Follow-up changes expected. - Are you including unit tests for the changes and scenario tests if relevant? - [x] Yes - [ ] No - Did you add public API? - [ ] Yes - [x] No - Does the change make any security assumptions or guarantees? - [ ] Yes - [x] No **🤖 Posted by AspireAgent (AI Agent)** Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Description
Fixes an untracked intermittent Windows CI failure in
Aspire.Hosting.Java.Tests.AddJavaContainerTests.AddJavaContainer_ExportsTelemetryToAspire:Root cause
DcpDependencyCheck.GetDcpInfoAsyncrunsdcp info. When the container runtime CLI is slow or hangs (common on loaded Windows runners), DCP hits its internal ~10s deadline and still returns JSON, but with"runtime":""and"hostName":""(error:context deadline exceeded).DcpContainersInfo.ContainerHostNamewasHostName ?? <runtime default>, so the empty string bypassed the fallback.HostUrlthen seturi.Host = "", so the container got anOTEL_EXPORTER_OTLP_ENDPOINTwith no host. Each failing test took about 10s, which matches DCP's internal timeout. The test computes its expected value from the sameContainerHostName, which is why CI shows "expected"http://:4317.This is a product bug, not just a test bug. Under the same conditions, a real app would give containers an unusable OTLP endpoint.
Fix
DcpContainersInfo.ContainerHostName: treat an empty or nullHostNameas missing and fall back to the runtime default (host.docker.internal/host.containers.internal).DcpExecutor.ContainerHostNameandContainerNetworkEndpointProvisioner.GetContainerHostNameAsyncread the rawHostNamedirectly. They now useContainerHostName, so all consumers agree.No assertions were weakened, and no sleeps or retries were added.
Evidence
Main
ci.ymlfirst attempts from 2026-10-23 to 2026-10-30 (63 runs, all attempt 1; no reruns):Hosting.Java (windows-latest)failed in 4 jobs with the identical assertion.Hosting.Java (ubuntu-latest)had no failures. Denominator: 51 of the 63 runs reached the Hosting.Java jobs (the other 12 were cancelled). On Windows, 4 of 51 first-attempt jobs failed with this assertion. 3 more failed only because the hosted runner lost communication (#20165), and 44 passed. On Ubuntu, 0 of 51 failed.Native repro (Linux, DCP 0.27.2): with a
dockershim onPATHthat runssleep 600,dcp inforeturns after 10.04s with"runtime":"","hostName":"". A healthy docker returns"hostName":"host.docker.internal". Feeding that JSON through the old logic producedOTEL_EXPORTER_OTLP_ENDPOINT='http:'. With the fix it producedhttp://host.docker.internal:4317.Regression tests (Aspire.Hosting.Tests):
DcpDependencyCheckTests.ContainerHostName_FallsBackWhenDcpReportsNoHostNamedeserializes real DCP JSON. It covers the timeout output, podman with an empty hostName, a missing hostName, and a custom hostName.ExpressionResolverTests.HostUrlInOtlpExporterEndpointUsesFallbackHostWhenDcpReportsEmptyHostName.DcpDependencyCheckTestscases fail with"", and the ExpressionResolver test fails withhttp://, the exact CI symptom.DcpDependencyCheckTests9/9 andExpressionResolverTests50/50 pass.Notes
maincurrently fails to compile (CS7036includeDocsatAtsGoCodeGenerator.ApiProjection.cs:419, a Addaspire sdk export -l go(Go API reference exporter) #21195/Emit godoc from ATS documentation metadata in the Go SDK generator #21197 conflict that another fix owns). Until that lands, CI on this PR may fail for that reason, which is unrelated to this change.Checklist
🤖 Posted by AspireAgent (AI Agent)