microsoft / microsoft/aspire

Yarp can not resolve service name

Open
#10,304 9 comments 0 reactions 0 assignees View on GitHub
area-integrations yarp
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

I have added `Aspire.Hosting.Yarp` to the apphost project. And followed the installation steps in the documentation.
When I startup the apphost, the api gateway aka yarp starts normally. Whenever I do a request that should be redirected to a service i get the error ` Request: An error was encountered before receiving a response.
System.Net.Http.HttpRequestException: Name or service not known (apiservice:443)
---> System.Net.Sockets.SocketException (0xFFFDFFFF): Name or service not known`

Could this be an issue with ssl, or am I doing something wrong?

### Expected Behavior

Yarp should return the page of the proxied api service

### Steps To Reproduce

My yarp.json:
```json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Information"
}
},
"AllowedHosts": "*",
"ReverseProxy": {
"Routes": {
"api": {
"ClusterId": "api",
"Match": {
"Path": "/api/{**catch-all}"
},
"Transforms": [
{ "PathRemovePrefix": "/api" }
]
}
},
"Clusters": {
"api": {
"Destinations": {
"api": {
"Address": "https+http://apiservice"
}
}
}
}
}
}
```

My aspire apphost:

```csharp
IResourceBuilder apiService = builder.AddProject("apiservice");

builder.AddYarp("apigateway")
.WithConfigFile("yarp.json")
.WithReference(apiService);
```

1. Start AppHost
2. go to the url `http://localhost:/api/scalar/v1`
3. Watch the console in aspire of the apigateway

### Exceptions (if any)

```
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:60049/api/scalar/v1 - - -
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'api'
info: Yarp.ReverseProxy.Forwarder.HttpForwarder[9]
Proxying to https://apiservice/scalar/v1 HTTP/2 RequestVersionOrLower
warn: Yarp.ReverseProxy.Forwarder.HttpForwarder[48]
Request: An error was encountered before receiving a response.
System.Net.Http.HttpRequestException: Name or service not known (apiservice:443)
---> System.Net.Sockets.SocketException (0xFFFDFFFF): Name or service not known
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Net.Sockets.Socket.g__WaitForConnectWithCancellation|285_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.InjectNewHttp2ConnectionAsync(QueueItem queueItem)
at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionWaiter`1.WaitForConnectionWithTelemetryAsync(HttpRequestMessage request, HttpConnectionPool pool, Boolean async, CancellationToken requestCancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.Metrics.MetricsHandler.SendAsyncWithMetrics(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at Yarp.ReverseProxy.Forwarder.HttpForwarder.SendAsync(HttpContext context, String destinationPrefix, HttpMessageInvoker httpClient, ForwarderRequestConfig requestConfig, HttpTransformer transformer, CancellationToken cancellationToken)
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint 'api'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished HTTP/1.1 GET http://localhost:60049/api/scalar/v1 - 502 0 - 3997.6699ms
```

### .NET Version info

.NET SDK:
Version: 10.0.100-preview.5.25277.114
Commit: ddf39a1b46
Workload version: 10.0.100-manifests.a07d1f1a
MSBuild version: 17.15.0-preview-25277-114+ddf39a1b4

Project version: net9.0
yarp aspire version: 9.3.1-preview.1.25305.6

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.