Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 8, 2025

Running dotnet watch run --no-hot-reload fails with "address already in use" errors after file changes because the process cleanup timeout was set to 0 seconds in no-hot-reload mode, force-killing the dev server before it could release network ports.

Changes

  • EnvironmentOptions.cs: Remove conditional logic that returned TimeSpan.FromSeconds(0) for no-hot-reload mode. Always return 5-second default timeout regardless of hot reload state to allow graceful shutdown.

  • EnvironmentOptionsTests.cs: Add tests verifying timeout behavior returns 5 seconds for both hot reload enabled/disabled cases, and respects environment variable overrides.

// Before
public TimeSpan GetProcessCleanupTimeout(bool isHotReloadEnabled)
    => ProcessCleanupTimeout ?? (isHotReloadEnabled ? TimeSpan.FromSeconds(5) : TimeSpan.FromSeconds(0));

// After  
public TimeSpan GetProcessCleanupTimeout(bool isHotReloadEnabled)
    => ProcessCleanupTimeout ?? TimeSpan.FromSeconds(5);

The DOTNET_WATCH_PROCESS_CLEANUP_TIMEOUT_MS environment variable can still override the default timeout.

Original prompt

This section details on the original issue you should resolve

<issue_title>[.NET10RC2] dotnet watch run --no-hot-reload fails</issue_title>
<issue_description>### Describe the bug
Running dotnet watch run --no-hot-reload does not work correctly, at least for blazor-wasm projects.
When a rebuild is triggered, it does not shut down the old dev server, causing the new one to fail with a bind error.

To Reproduce

  • Create new blazor wasm app (ie. dotnet new blazorwasm -e -p --no-https)
  • Run with watch: dotnet watch run -c Release --property WarningLevel=0 --no-hot-reload
  • Open in browser
  • Make a change to one of the .razor files (ie. Home.razor)
  • Note that the server fails to start
  • Reload the page, note that the browser console is spammed with integrity errors due to not being able to find files.

Exceptions (if any)

fail: Microsoft.Extensions.Hosting.Internal.Host[11]
      Hosting failed to start
      System.IO.IOException: Failed to bind to address http://[::]:5117: address already in use.
       ---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use
       ---> System.Net.Sockets.SocketException (98): Address already in use
         at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, Boolean disconnectOnFailure, String callerName)
         at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
         at System.Net.Sockets.Socket.Bind(EndPoint localEP)
         at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportOptions.CreateDefaultBoundListenSocket(EndPoint endpoint)
         at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()
         --- End of inner exception stack trace ---
         at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()
         at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TransportManager.BindAsync(EndPoint endPoint, ConnectionDelegate connectionDelegate, EndpointConfig endpointConfig, CancellationToken cancellationToken)
         at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.<>c__DisplayClass28_0`1.<<StartAsync>g__OnBind|0>d.MoveNext()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context, CancellationToken cancellationToken)
         --- End of inner exception stack trace ---
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context, CancellationToken cancellationToken)
         at Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
         at Microsoft.AspNetCore.Server.Kestrel.Core.AnyIPListenOptions.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
         at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
         at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
         at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
         at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__14_1(IHostedService service, CancellationToken token)
         at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)

Further technical details

details of dotnet --info

``` .NET SDK: Version: 10.0.100-rc.2.25502.107 Commit: 89c8f6a112 Workload version: 10.0.100-manifests.0cee6f9c MSBuild version: 18.0.0-preview-25502-107+89c8f6a11

Runtime Environment:
OS Name: nixos
OS Version: 25.11
OS Platform: Linux
RID: linux-x64
Base Path: /nix/store/aj7lxjjn3rl2bazsv9p0dfnv069j6rsq-dotnet-sdk-10.0.100-rc.2.25502.107/share/dotnet/sdk/10.0.100-rc.2.25502.107/

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.0-rc.2.25502.107
Architecture: x64
Commit: 89c8f6a112

.NET SDKs installed:
10.0.100-rc.2.25502.107 [/nix/store/aj7lxjjn3rl2ba...


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: tmat <41759+tmat@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants