Fix Kafka AppHost health-check producer lifetime
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 KafkaHealthCheck as 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
- Added public-API regression coverage for DI ownership, reuse across scopes, resource isolation, and connection-string availability. No private reflection.
- All 28 selected Kafka hosting tests passed, including broker-backed health and
WaitForreadiness tests. - Ran standalone AppHosts with two real Kafka 8.2.0 brokers each, comparing released 13.5.3 with the patched source. Both used Confluent.Kafka 2.15.0, normal resource monitoring, and 40 additional rounds through
HealthCheckService. All 80 additional probe results were healthy.
| Live measurement | Released 13.5.3 | Patched |
|---|---|---|
| Total health-check executions | 84 | 84 |
| Distinct health-check instances | 84 | 2 |
| Producer polling threads after the checks | 84 | 2 |
| Producer polling threads after AppHost disposal | 84 | 0 |
Polling threads were identified using dotnet-stack while 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
- 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
- If yes, did you have an API Review for it?
- Yes
- No
- Did you add
<remarks />and<code />elements on your triple slash comments?- Yes
- No
- If yes, did you have an API Review for it?
- No
- Yes
- Does the change make any security assumptions or guarantees?
- Yes
- If yes, have you done a threat model and had a security review?
- Yes
- No
- If yes, have you done a threat model and had a security review?
- No
- Yes