aspire icon indicating copy to clipboard operation
aspire copied to clipboard

On dashboard startup, check if ports are in use before starting Kestrel

Open JamesNK opened this issue 9 months ago • 4 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

If the dashboard is started while a previous instance is running the user sees an unfriendly error message that the port is already in use. This will cause the dashboard startup to fail.

Describe the solution you'd like

Two things:

  1. Poll if ports are in use. If they are then wait a short time (5 seconds?) and try again. Makes dashboard more resilient
  2. Throw a friendly error message to the user.

Additional context

No response

JamesNK avatar Apr 08 '25 23:04 JamesNK

@davidfowl

Providing a more friendly error message when ports are in use is a good improvement and I think we should do it. What do you think about a small delay to wait if they're not available?

JamesNK avatar Apr 09 '25 03:04 JamesNK

A better error is fine, I don't think the dashboard should do anything to restart itself though. Do that in the app host.

davidfowl avatar Apr 09 '25 03:04 davidfowl

I agree on not restarting if there is an error during startup.

But what about:

for (var i = 0; i < 5; i++)
{
    if (PortsAvailable())
    {
        return;
    }
    await Task.Delay(1000);
}

throw new Exception("Friendly error message that dashboard ports are in use here.");

Worth having a small wait on startup for ports to become available? Or just leave this out and have DCP retry restarting the dashboard if there is any error? I'm leaning towards leaving it all up to DCP but just want to double check.

JamesNK avatar Apr 09 '25 04:04 JamesNK

I'd vote for robustness in depth, given this is a complex multiprocess system...

danmoseley avatar Apr 09 '25 14:04 danmoseley