Reputation: 141
I am running an .net core web application and using dotnet watch run to monitor the changes and restart the application when changes are made.
I am getting an error thrown within the terminal when the command is triggered through a file change.
watch : Exited with error code 143
The end result of this is that when the application restarts it tries to attach to the same port and an error is thrown.
System.IO.IOException: Failed to bind to address http://localhost:5000 on the IPv4 loopback interface: port already in use. ---> System.AggregateException: One or more errors occurred. (Error -4091 .......
To resolve the issue you need to find the tasks and kill them manually then the port is freed up.
When running the application through dotnet run and manually closing through Ctrl+C i am not having any issues.
I am using .NET Command Line Tools (1.0.3) I have also had this issue on .NET Command Line Tools (1.0.1) I upgraded to try and resolve the issue.
Upvotes: 4
Views: 7839
Reputation: 26763
To resolve the issue you need to find the tasks and kill them manually then the port is freed up.
I would recommend opening an issue on dotnet-watch. https://github.com/aspnet/DotNetTools/issues. I would need more details to investigate this, but it appears that when dotnet-watch is attempting to restart your web application, the shutdown does not complete gracefully and may leave behind an orphaned process. This could be a bug in the shutdown logic from your app, or it could be a bug in dotnet-watch's process handling.
Upvotes: 3