microsoft / microsoft/aspire

WithHttpProbe throws duplicate health check error when using same path for different probe types

Open
#14,302 0 comments 2 reactions 0 assignees View on GitHub
area-app-model
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

## Description

When calling `WithHttpProbe` multiple times on the same resource with **different probe types** but the **same path**, Aspire throws an exception about duplicate health check keys.

## Reproduction

```csharp
var hashr = builder.AddProject("myapp")
.WithHttpProbe(ProbeType.Startup, "/alive", initialDelaySeconds: 5, periodSeconds: 5, timeoutSeconds: 10)
.WithHttpProbe(ProbeType.Liveness, "/alive", initialDelaySeconds: 30, periodSeconds: 30, timeoutSeconds: 10);
```

## Error

```
Unhandled exception. Aspire.Hosting.DistributedApplicationException: Resource 'myapp' already has a health check with key 'myapp_https_/alive_200_check'.
at Aspire.Hosting.ResourceBuilderExtensions.WithHealthCheck[T](IResourceBuilder1 builder, String key)
at Aspire.Hosting.ResourceBuilderExtensions.WithHttpHealthCheck[T](...)
at Aspire.Hosting.ResourceBuilderExtensions.WithHttpProbe[T](...)
```

## Expected Behavior

It should be valid to use the same health check endpoint path for different probe types (Startup, Liveness, Readiness). The health check key generation should incorporate the probe type to ensure uniqueness, e.g.:
- `myapp_https_/alive_200_startup_check`
- `myapp_https_/alive_200_liveness_check`

Alternatively, if the same path is used for multiple probes, the underlying health check could be shared/reused rather than attempting to register a duplicate.

## Workaround

Use different paths for each probe type:

```csharp
var hashr = builder.AddProject("myapp")
.WithHttpProbe(ProbeType.Startup, "/startup", ...)
.WithHttpProbe(ProbeType.Liveness, "/alive", ...);
```

## Context

This is a common scenario where applications have a single lightweight health endpoint that should be used for both startup and liveness probes (e.g., Kubernetes-style health checks).

## Environment

- Aspire version: 13.1.0
- .NET version: 10.0

Contributor guide

Open the contributing guide

Research direction

Start at the WithHttpProbe and WithHttpHealthCheck entry points named in the stack trace, then reproduce the issue with the two /alive probes from the example. Trace how health check keys are generated and inspect nearby tests for probe registration. Done means the same path can be used for different probe types without a duplicate-key exception, with coverage for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.