Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only one usage of each socket address errors when restarting app host #6693

Open
1 task done
afscrome opened this issue Nov 15, 2024 · 3 comments
Open
1 task done
Assignees
Milestone

Comments

@afscrome
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Every time I restart my aspire project, I am getting a bunch of "Only one usage of each socket address" errors. The only way I can avoid getting these errors is to explicitly kill the already running app host instance before starting a new one. I haven't seen this on my work machine, but am consistently seeing it on my personal machine.

fail: Aspire.Hosting.Dcp.dcpctrl.ServiceReconciler[0]
      could not start the proxy {"ServiceName": {"name":"apiservice-https"}, "Reconciliation": 9, "error": "could not start the proxy for the service: listen tcp [::1]:7415: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted."}

Expected Behavior

No errors on startup.

Steps To Reproduce

  1. Have an AppHost project in VS
  2. Start without debugging
  3. Start without debugging again to restart the app
20241115-2114-36.4003668.mp4

Don't think the contents of my project is relevant, but it's essentially the starter project

using AspireInitalisation.AppHost;
using Microsoft.Extensions.DependencyInjection;

var builder = DistributedApplication.CreateBuilder(args);

var cache = builder.AddRedis("cache");

var apiService = builder.AddProject<Projects.AspireInitalisation_ApiService>("apiservice");

builder.AddProject<Projects.AspireInitalisation_Web>("webfrontend")
    .WithExternalHttpEndpoints()
    .WithReference(cache)
    .WaitFor(cache)
    .WithReference(apiService)
    .WaitFor(apiService);

var sql = builder.AddSqlServer("sql").WithLifetime(ContainerLifetime.Persistent);

var db = sql.AddDatabase("mydb");

var init = builder.AddExecutable("init", "pwsh", ".", "-Command", """
        $wait = 10
        Write-Host Waiting $wait Seconds
        Start-Sleep -Seconds $wait
        Write-Host Done
        """);

//db.WithInitaliserAsHealthCheck(init);

builder.Build().Run();

Exceptions (if any)

fail: Aspire.Hosting.Dcp.dcpctrl.ServiceReconciler[0]
could not start the proxy {"ServiceName": {"name":"apiservice-http"}, "Reconciliation": 7, "error": "could not start the proxy for the service: listen tcp [::1]:5321: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted."}
fail: Aspire.Hosting.Dcp.dcpctrl.ServiceReconciler[0]
could not start the proxy {"ServiceName": {"name":"webfrontend-https"}, "Reconciliation": 8, "error": "could not start the proxy for the service: listen tcp [::1]:7249: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted."}
fail: Aspire.Hosting.Dcp.dcpctrl.ServiceReconciler[0]
could not start the proxy {"ServiceName": {"name":"webfrontend-http"}, "Reconciliation": 9, "error": "could not start the proxy for the service: listen tcp [::1]:5244: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted."}
fail: Aspire.Hosting.Dcp.dcpctrl.ServiceReconciler[0]
could not start the proxy {"ServiceName": {"name":"apiservice-https"}, "Reconciliation": 12, "error": "could not start the proxy for the service: listen tcp [::1]:7415: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted."}
fail: Aspire.Hosting.Dcp.dcpctrl.ServiceReconciler[0]
could not start the proxy {"ServiceName": {"name":"apiservice-https"}, "Reconciliation": 15, "error": "could not start the proxy for the service: listen tcp [::1]:7415: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted."}
fail: Aspire.Hosting.Dcp.dcpctrl.ServiceReconciler[0]
could not start the proxy {"ServiceName": {"name":"apiservice-http"}, "Reconciliation": 16, "error": "could not start the proxy for the service: listen tcp [::1]:5321: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted."}

.NET Version info

.NET SDK:
 Version:           9.0.100
 Commit:            59db016f11
 Workload version:  9.0.100-manifests.b7b342be
 MSBuild version:   17.12.7+5b8665660

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100\

.NET workloads installed:
 [aspire]
   Installation Source: VS 17.12.35506.116
   Manifest Version:    9.0.0-preview.4.24454.4/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\9.0.0-preview.4.24454.4\WorkloadManifest.json
   Install Type:              Msi

Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.0
  Architecture: x64
  Commit:       9d5a6a9aa4

.NET SDKs installed:
  8.0.404 [C:\Program Files\dotnet\sdk]
  9.0.100-rc.2.24474.11 [C:\Program Files\dotnet\sdk]
  9.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0-rc.2.24474.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0-rc.2.24473.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.0-rc.2.24474.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Anything else?

Image

  <ItemGroup>
    <PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0" />
    <PackageReference Include="Aspire.Hosting.Redis" Version="9.0.0" />
    <PackageReference Include="Aspire.Hosting.SqlServer" Version="9.0.0" />
  </ItemGroup>
@karolz-ms
Copy link
Member

Thank you for the report, @afscrome . I have a strong suspicion this is a timing issue. The stopping on of the project Executable, and the stopping of associated Endpoint proxies happens asynchronously. If the Executable gets re-created quickly (which is the case during restart), and if it uses fixed ports (which .NET projects typically do), the proxies from the previous run might still occupy the ports.

We probably need to delay reporting the Executable until all its Endpoints are gone. At least if the Executable is using fixed ports.

Containers may have the same problem actually.

@JamesNK FYI

@karolz-ms
Copy link
Member

@dbreshears pointed out this is AppHost restart, not project restart. Still it is a timing issue associated with the port checks and the previous instance not freeing up the ports/stopping the proxies fast enough. The solution here is probably to re-try the project startup and port allocation (new instance)

@alan-null
Copy link

hey @karolz-ms

I am facing the same issue. Tried different things already, nothing helped so far

  • David mentioned in .NET Aspire Starter Application not working.. #4257 that it might be something with IPv6 - I used environment variable and switched to v4 "DCP_IP_VERSION_PREFERENCE": "IPv4", - I can confirm proxy was setup with ipv4 but problem persists
  • I tried to disable firewall
  • I tried to change ports (I hope I got you right) but for me each new run result with the same issue - you can see error with ports that haven't been used before
    Image

Not sure if this will be helpful in any way but I uploaded my project here: aspire_issue_6693 - it's a fresh solution with api project + orchestrator

CC: @afscrome

@joperezr joperezr added the untriaged New issue has not been triaged label Nov 18, 2024
@karolz-ms karolz-ms self-assigned this Nov 19, 2024
@joperezr joperezr added this to the Backlog milestone Nov 20, 2024
@joperezr joperezr removed the untriaged New issue has not been triaged label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants