Yarp with Replicas does not distribute requests
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
On Aspire.AppHost 9.3.0, given the following `Program.cs`:
```
var builder = DistributedApplication.CreateBuilder(args);
var api = builder.AddProject("bike-rental-api")
.WithReplicas(2)
.WithHttpEndpoint(7001);
builder.AddYarp("apigateway")
.WithConfigFile("yarp.json")
.WithReference(api).WaitFor(api);
builder.Build().Run();
```
and the following `yarp.json`:
```
{
"ReverseProxy": {
"Routes": {
"apiRoutes": {
"ClusterId": "bike-rental-api",
"Match": {
"Path": "/api/{**catch-all}"
}
}
},
"Clusters": {
"bike-rental-api": {
"LoadBalancingPolicy": "RoundRobin",
"Destinations": {
"all": {
"Address": "http+https://bike-rental-api"
}
}
}
}
}
}
```
all requests I make on `apigateway` are forwarded to the same `bike-rental-api` instance.
### Expected Behavior
Because I set `LoadBalancingPolicy` to `RoundRobin` I expect the requests to be evenly split to the two instances of `bike-rental-api`.
### Steps To Reproduce
- Create a new Solution
- Create an api project with a simple endpoint (stands for bike-renatal-api)
- Generate service defaults and use it in the api project
- Generate an appHost and copy my code (Program and Yarp)
- Start the solution
- Open the dashboard and open the reverse proxy (yarp)
- Make several calls to the endpoint you created on the api
- Go to the traces view in the aspire dashboard and look where the calls are forwarded to
-> The calls are all forwarded to the same instance
### Exceptions (if any)
_No response_
### .NET Version info
_No response_
### Anything else?
In the console of the yarp instance I can see something like
```
Waiting for resource 'bike-rental-api' to enter the 'Running' state.
Waiting for resource ready to execute for 'bike-rental-api-szdevtvq'.
Finished waiting for resource 'bike-rental-api-szdevtvq'.
Waiting for resource ready to execute for 'bike-rental-api-hgkqrvga'.
Finished waiting for resource 'bike-rental-api-hgkqrvga'.
```
So, it looks like somehow yarp knows about the two instances.
Contributor guide
Assessment
This issue has not been assessed yet.