Skip to content

Service discovery seems to broken for python/uvicorn resources #14411

@johanndev

Description

@johanndev

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Reproduction

https://github.com/johanndev/aspire-service-discovery-repro

Description

While investigating why the Scalar integration was unable to load the openapi document of my fastapi app, I discovered that service discovery seems to have stopped working altogether for uvicorn resources.

apphost:

#:sdk Aspire.AppHost.Sdk@13.2.0-preview.1.26109.1
#:package Aspire.Hosting.Python@13.2.0-preview.1.26109.1
#:package Scalar.Aspire@0.8.45

#:project ./mainapi/mainapi.csproj
#:project ./downstreamapi/downstreamapi.csproj

using Scalar.Aspire;

var builder = DistributedApplication.CreateBuilder(args);

var fastapi = builder.AddUvicornApp("fastapi", "./fastapi", "main:app")
    .WithUv()
    .WithExternalHttpEndpoints();

var downstreamapi = builder.AddProject<Projects.downstreamapi>("downstreamapi")
    .WithExternalHttpEndpoints()
    .WithReference(fastapi)
    .WaitFor(fastapi);

var mainapi = builder.AddProject<Projects.mainapi>("mainapi")
    .WithExternalHttpEndpoints()
    .WithReference(fastapi)
    .WaitFor(fastapi)
    .WithReference(downstreamapi)
    .WaitFor(downstreamapi);

var scalar = builder.AddScalarApiReference()
    .WithApiReference(fastapi, options =>
    {
        options
            .AddDocument("openapi", "FastApi OpenAPI")
            .WithOpenApiRoutePattern("/openapi.json");
    })
    .WithApiReference(downstreamapi)
    .WaitFor(mainapi);

builder.Build().Run();

I have to two endpoints in my main api:

  • One calls an endpoint in the downstream resource http://downstreamapi/testendpoint <- Works
  • One calls an endpoint in the fastapi resource via http://fastapi/testendpoint <- Fails: HttpRequestException: No such host is known. (fastapi:80)

I verified that calling the fastapi endpoint directly works as expected: https://fastapi-aspire-service-discovery-repro.dev.localhost:52163/testendpoint -> 200 OK

Expected Behavior

Calls to a uvicorn app via aspire-assigned DNS-name works.

Steps To Reproduce

The second call fails with HttpRequestException: No such host is known. (fastapi:80)

Exceptions (if any)

No response

.NET Version info

10.0.100

Anything else?

aspire doctor

Aspire Environment Check
========================

.NET SDK
  ✓  .NET 10.0.100 installed (x64)
  ✓  HTTPS development certificate is trusted

Container Runtime
  ✓  Podman detected and running (version 5.7.1)

Summary: 3 passed, 0 warnings, 0 failed

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplicationpython

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions