Fix Kafka AppHost health-check producer lifetime - #20092
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 20092Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 20092" |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Copilot review overview
Review tier: Balanced
Findings: None
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
PR Testing ReportPR Information
Artifact Version Verification
Changes Analyzed
Test Scenario ExecutedFresh packaged AppHost lifecycle, including outage and recoveryObjective: Validate the shipped PR artifacts, real resource orchestration, dashboard state, health-check reuse, and disposal without private reflection. Status: Passed. Created a fresh file-based C# AppHost using the installed PR CLI and the explicit PR template hive: "$cli" new aspire-empty --name KafkaPrSmoke --output "$temp/KafkaPrSmoke" \
--source "$hive" --version 13.6.0-pr.20092.g15c2c650 \
--language csharp --localhost-tld false --suppress-agent-init --non-interactiveAdded the PR-version Kafka package and two "$cli" start --apphost "$apphost" --launch-profile http --isolated --format Json --non-interactiveThe temporary harness observed public health-check factory results and captured managed stacks using All phases deliberately used the same fresh AppHost so reuse could be verified across failure and recovery:
All CLI follow-up commands supplied the explicit Lifetime observationsCounts include normal background monitoring as well as explicit probe rounds.
The captured thread stacks contain EvidencePreserved under the session's
Installation, template creation, broker lifecycle, and Summary
Overall ResultPR Kafka behavior verified against the packaged artifacts. At the end of this test run, CI had failed VS Code browser-debugger E2E jobs on Linux and Windows, with the aggregate test/final checks consequently failed. Those jobs are outside the changed Kafka area and were not diagnosed by this focused run; their cause is not established here. CleanupThe AppHost and detached CLI processes exited; both owned broker containers were removed; the isolated headless browser was closed. The temporary project and PR installation were deleted. Evidence and the harness were retained in session artifacts. The repository working tree remained clean. |
|
/backport to release/13.5 |
|
Started backporting to |
Register a DI-owned keyed singleton per Kafka resource so repeated health checks reuse their producer and AppHost disposal releases it. Add public-API coverage for singleton ownership, resource isolation, and deferred connection-string availability. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
15c2c65 to
f1aa806
Compare
Tests selector2 / 99 PR test projects · 2 PR jobs · 0 advisory-only targets, from 2 changed files. Selected PR test projects (2 / 99)
Selected PR jobs (2)
Advisory workflow impact (0)none How these were chosen — grouped by what changed🔧 🧪 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. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
James Newton-King (JamesNK)
left a comment
There was a problem hiding this comment.
Reviewed the Kafka health-check lifetime change and regression coverage. 0 issues found.
Updated [Aspire.Hosting.AppHost](https://github.com/microsoft/aspire) from 13.5.3 to 13.5.4. <details> <summary>Release notes</summary> _Sourced from [Aspire.Hosting.AppHost's releases](https://github.com/microsoft/aspire/releases)._ ## 13.5.4 ## What's New in Aspire 13.5.4 Patch release for Aspire 13.5 that fixes Kafka health-check resource leaks, DevTunnel errors with automatically selected regions, misleading Azure emulator dashboard entries, and unintended changes to generated starter apps, plus Homebrew compatibility and Radius API diagnostic updates. ### 🐛 Fixes - 📨 **Kafka health checks leaked producers and polling threads** — Each AppHost health-check execution created a new Kafka producer without disposing it, accumulating background threads over time. Health checks now reuse a producer per Kafka resource and dispose it with the AppHost, while keeping multiple Kafka resources independently configured. Fixes [#20091](microsoft/aspire#20091). ([#20094](microsoft/aspire#20094), backport of [#20092](microsoft/aspire#20092), @davidfowl) - 🌐 **DevTunnels could fail when the region was selected automatically** — Tunnel setup and health checks now use the cluster-qualified tunnel ID returned by the DevTunnel CLI for port operations and access queries. This fixes failures when a bare tunnel ID cannot be resolved for those operations. Regression introduced in 13.3. Fixes [#18790](microsoft/aspire#18790). ([#19853](microsoft/aspire#19853), backport of [#19230](microsoft/aspire#19230), @Vladipz) - ☁️ **Emulator-only AppHosts showed an unused Azure environment** — The dashboard now hides the `azure-environment` resource when no Azure resources require cloud provisioning, instead of leaving it visible in **Not started**. It remains visible for apps that combine local emulators with resources requiring Azure provisioning. No AppHost changes are needed. Fixes [#19617](microsoft/aspire#19617). ([#19998](microsoft/aspire#19998), backport of [#19843](microsoft/aspire#19843), @eerhardt) - 🧩 **Starter app generation could alter unrelated JavaScript values** — Dynamic port replacement could also replace matching numeric literals in bundled JavaScript, including Bootstrap timing values. Port substitutions are now restricted to `localhost:` URLs, preserving the original library files while still configuring the requested ports. Fixes [#20030](microsoft/aspire#20030). ([#20110](microsoft/aspire#20110), backport of [#20031](microsoft/aspire#20031), @bart-vmware, @JamesNK) - 🍎 **Updated the Aspire Homebrew cask for Homebrew 6.x** — Replaced deprecated cask URL and post-install syntax with the supported equivalents, resolving compatibility issues with current Homebrew while preserving install-channel metadata. ([#20119](microsoft/aspire#20119), backport of [#19965](microsoft/aspire#19965), @askpt, @joperezr) - 🧪 **Radius cloud-provider callback interfaces now carry the experimental diagnostic** — `IAwsRadiusProviderBuilder` and `IAzureRadiusProviderBuilder` are now marked with `ASPIRERADIUS003`, matching the existing `WithAwsProvider` and `WithAzureProvider` methods. Code referencing these interfaces directly must now acknowledge the same experimental API diagnostic. ([#19874](microsoft/aspire#19874), @sebastienros) --- *Full Changelog: [v13.5.3...v13.5.4](microsoft/aspire@v13.5.3...v13.5.4)* *Full commit: [9c1b401dd67746739044f68959cbf4d3d7af93a6](microsoft/aspire@9c1b401dd67746739044f68959cbf4d3d7af93a6)* Commits viewable in [compare view](microsoft/aspire@v13.5.3...v13.5.4). </details> Updated [Scalar.AspNetCore](https://github.com/scalar/scalar) from 2.17.3 to 2.17.6. <details> <summary>Release notes</summary> _Sourced from [Scalar.AspNetCore's releases](https://github.com/scalar/scalar/releases)._ No release notes found for this version range. Commits viewable in [compare view](https://github.com/scalar/scalar/commits). </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Josh Hufford <josh@hufford.io>
Description
Kafka AppHost health checks currently create a new producer on every execution without disposing it, accumulating polling threads over time. Register each resource's
KafkaHealthCheckas a DI-owned keyed singleton so checks reuse their producer and AppHost disposal releases it.This preserves independent configuration for multiple Kafka resources and deferred connection-string initialization, following the existing client integration pattern. No public API, dependency, or producer-default changes are required.
Fixes: #20091
Validation
WaitForreadiness tests.HealthCheckService. All 80 additional probe results were healthy.Polling threads were identified using
dotnet-stackwhile the process remained alive after AppHost disposal. The standalone verification used no private reflection. Detailed evidence is attached to #20091. This verifies the lifetime leak, not the original report's exact CPU percentage.Checklist
<remarks />and<code />elements on your triple slash comments?