Skip to content

Fall back to default container host name when DCP reports an empty one - #21432

Merged
Karol Zadora-Przylecki (karolz-ms) merged 2 commits into
mainfrom
aspireagent/fix-empty-dcp-container-hostname
Oct 30, 2026
Merged

Karol Zadora-Przylecki (karolz-ms) merged 2 commits into
mainfrom
aspireagent/fix-empty-dcp-container-hostname

Conversation

@davidfowl

@davidfowl David Fowler (davidfowl) commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Fixes an untracked intermittent Windows CI failure in Aspire.Hosting.Java.Tests.AddJavaContainerTests.AddJavaContainer_ExportsTelemetryToAspire:

Expected: "http://:4317"
Actual:   "http://"
   at AddJavaContainerTests.cs:124

Root cause

DcpDependencyCheck.GetDcpInfoAsync runs dcp 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.ContainerHostName was HostName ?? <runtime default>, so the empty string bypassed the fallback. HostUrl then set uri.Host = "", so the container got an OTEL_EXPORTER_OTLP_ENDPOINT with no host. Each failing test took about 10s, which matches DCP's internal timeout. The test computes its expected value from the same ContainerHostName, 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 null HostName as missing and fall back to the runtime default (host.docker.internal / host.containers.internal).
  • DcpExecutor.ContainerHostName and ContainerNetworkEndpointProvisioner.GetContainerHostNameAsync read the raw HostName directly. They now use ContainerHostName, so all consumers agree.

No assertions were weakened, and no sleeps or retries were added.

Evidence

Main ci.yml first 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 docker shim on PATH that runs sleep 600, dcp info returns after 10.04s with "runtime":"","hostName":"". A healthy docker returns "hostName":"host.docker.internal". Feeding that JSON through the old logic produced OTEL_EXPORTER_OTLP_ENDPOINT='http:'. With the fix it produced http://host.docker.internal:4317.

Regression tests (Aspire.Hosting.Tests):

  • DcpDependencyCheckTests.ContainerHostName_FallsBackWhenDcpReportsNoHostName deserializes real DCP JSON. It covers the timeout output, podman with an empty hostName, a missing hostName, and a custom hostName.
  • ExpressionResolverTests.HostUrlInOtlpExporterEndpointUsesFallbackHostWhenDcpReportsEmptyHostName.
  • Before the fix (src stashed): 2 DcpDependencyCheckTests cases fail with "", and the ExpressionResolver test fails with http://, the exact CI symptom.
  • After the fix: DcpDependencyCheckTests 9/9 and ExpressionResolverTests 50/50 pass.

Notes

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)

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>
@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 -- 21432

Or

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

@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot October 30, 2026 06:22
@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.

🟡 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>

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 adding container-hostname fallbacks when DCP reports a missing hostname.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

52 / 100 PR test projects · 4 PR jobs, from 7 changed files.

Selected PR test projects (52 / 100)

Aspire.Cli.EndToEnd.Tests, Aspire.Hosting.Analyzers.Tests, Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Kusto.Tests, Aspire.Hosting.Azure.Provisioning.Tests, Aspire.Hosting.Azure.Tests, Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Browsers.Tests, Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.CodeGeneration.Java.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.Rust.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.Containers.Tests, Aspire.Hosting.DevTunnels.Tests, Aspire.Hosting.Docker.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.EntityFrameworkCore.Tests, Aspire.Hosting.Foundry.Tests, Aspire.Hosting.Garnet.Tests, Aspire.Hosting.Go.Tests, Aspire.Hosting.Java.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Kafka.Tests, Aspire.Hosting.Keycloak.Tests, Aspire.Hosting.Kubernetes.Tests, Aspire.Hosting.Maui.Tests, Aspire.Hosting.Milvus.Tests, Aspire.Hosting.MongoDB.Tests, Aspire.Hosting.MySql.Tests, Aspire.Hosting.Nats.Tests, Aspire.Hosting.OpenAI.Tests, Aspire.Hosting.Oracle.Tests, Aspire.Hosting.Orleans.Tests, Aspire.Hosting.PostgreSQL.Tests, Aspire.Hosting.Python.Tests, Aspire.Hosting.Qdrant.Tests, Aspire.Hosting.RabbitMQ.Tests, Aspire.Hosting.Radius.Tests, Aspire.Hosting.Redis.Tests, Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Rust.Tests, Aspire.Hosting.Seq.Tests, Aspire.Hosting.SqlServer.Tests, Aspire.Hosting.Testing.Tests, Aspire.Hosting.Tests, Aspire.Hosting.Valkey.Tests, Aspire.Hosting.Yarp.Tests, Aspire.Playground.Tests, Aspire.Templates.Tests

Selected PR jobs (4)

cli-starter-validation, extension-e2e, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

⚠️ 34 of the 52 selected test projects come from a single change — tests/Aspire.Hosting.TestUtilities/Dcp/TestDcpDependencyCheckService.cs.

🧪 tests/Aspire.Hosting.TestUtilities/Dcp/TestDcpDependencyCheckService.cs (changed test)
→ 34 via the project graph

show 34

Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Kusto.Tests, Aspire.Hosting.Browsers.Tests, Aspire.Hosting.Containers.Tests, Aspire.Hosting.DevTunnels.Tests, Aspire.Hosting.Docker.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.EntityFrameworkCore.Tests, Aspire.Hosting.Foundry.Tests, Aspire.Hosting.Garnet.Tests, Aspire.Hosting.Go.Tests, Aspire.Hosting.Java.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Kafka.Tests, Aspire.Hosting.Keycloak.Tests, Aspire.Hosting.Kubernetes.Tests, Aspire.Hosting.Milvus.Tests, Aspire.Hosting.MongoDB.Tests, Aspire.Hosting.MySql.Tests, Aspire.Hosting.Nats.Tests, Aspire.Hosting.OpenAI.Tests, Aspire.Hosting.Oracle.Tests, Aspire.Hosting.Orleans.Tests, Aspire.Hosting.PostgreSQL.Tests, Aspire.Hosting.Python.Tests, Aspire.Hosting.Qdrant.Tests, Aspire.Hosting.RabbitMQ.Tests, Aspire.Hosting.Redis.Tests, Aspire.Hosting.Rust.Tests, Aspire.Hosting.Seq.Tests, Aspire.Hosting.SqlServer.Tests, Aspire.Hosting.Valkey.Tests, Aspire.Hosting.Yarp.Tests

🔧 src/Aspire.Hosting/Dcp/ContainerNetworkEndpointProvisioner.cs (changed source)
→ 12 via the project graph: Aspire.Hosting.Analyzers.Tests (2 hops), Aspire.Hosting.Azure.Provisioning.Tests (3 hops), Aspire.Hosting.Azure.Tests, Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.CodeGeneration.Java.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.Rust.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.Maui.Tests, Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Testing.Tests (2 hops), Aspire.Playground.Tests

🧪 tests/Aspire.Hosting.Tests/Dcp/DcpDependencyCheckTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests
→ 3 via the project graph: Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.Radius.Tests

📦 affected project Aspire.Hosting.Dotnet
→ 2 tests: Aspire.Cli.EndToEnd.Tests, Aspire.Templates.Tests

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

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

Job reasons

Job Triggered by
cli-starter-validation affected project Aspire.Hosting.PostgreSQL
extension-e2e • src/Aspire.Hosting/Dcp/ContainerNetworkEndpointProvisioner.cs, src/Aspire.Hosting/Dcp/DcpExecutor.cs, src/Aspire.Hosting/Dcp/IDcpDependencyCheckService.cs
• affected project Aspire.Hosting
polyglot • affected project Aspire.Hosting
• affected project Aspire.Hosting.Azure.Provisioning
typescript-api-compat affected project Aspire.Hosting

Selection computed for commit 9d08ea6.

@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.

@karolz-ms
Karol Zadora-Przylecki (karolz-ms) merged commit d85136b into main Oct 30, 2026
1025 of 1033 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.0 milestone Oct 30, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

✅ No documentation update needed.

Step 5 branch: docs_optional → bug_fix_restores_documented_behavior. No signals triggered (signal_count 0). The PR makes ContainerHostName fall back to the runtime default (host.docker.internal / host.containers.internal) when DCP reports an empty host name. This is an internal fix. It adds no new public surface, option or string.

David Fowler (davidfowl) added a commit that referenced this pull request Nov 10, 2026
)

## 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>
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.

4 participants