Hi,
I installed dotnet core on Mac Sierra in order to build .net mvc application & while build a project I learned that donet\kestrel doesn't release the port 5000 after I stop a project causing port already in use error on next run.
I couldn't find any command\manual way to release\stop the port 5000 or localhost:500.
Please enlighten me if any such commend exists or any other possible solution.
error:
System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use. ---> Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.AddressInUseException: Error -48 EADDRINUSE address already in use ---> Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvException: Error -48 EADDRINUSE address already in use
Thanks much 馃憤
How did you run the application?
@davidfowl hey, using vscode: 'Start Debugging' command, and stopped the same way: Ctrl + C o 'Stop Debugging'
It has happened to me and what I did was change the port. Try using the command
c#
WebHost.CreateDefaultBuilder(args)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseUrls("http://*:5001")
.UseStartup<Startup>()
.Build();
@hugobritobh I don't think your understood the issues: Port has not been released by Kestrel, irrespective of whichever one you use.
@Eilon
Did you check with netstat -an| grep 5000 what state the port is in @foo-baar
@wfurt: I try with lsof -i:5000 it shows occupied by dotnet, so I kill it manually and then continue.

Thanks @foo-baar It really looks like the dotnet process is hogging the port.
I wanted to make sure this is not a race condition closing the port.
It's likely something to do with how the process is being launched. dotnet run doesn't forward control + c to the child process.
@wfurt : Welcome man, I have tested most of the basic features rest all happens to work fine, its my first time with core on mac, will check in case I face anything else.
@davidfowl : Hey, I have been launching it via vscode (not manually) However running kestrel server has no stop command, besides general Ctrl + C.
On a separate note I have posted it to kestrel team however I believe since its not a mainstream component for them I doubt they'll focus on it much.
Thanks 鉁岋笍
Ah, sounds like the old Ctrl-C is killing parent but not dotnet children: https://github.com/dotnet/cli/issues/7426
@omajid What is documented there makes sense, but I havn't had a chance to loot into the dohet processes hence can't comment anything on that.
Is there anything else that needs to be done here or can we close this issue out?
@Petermarcu I think we can close the issue, though it continue to exists today workaround is how to execute the code, i.e doing dotnet clean\build\run form terminal just runs fine, but if someone tries from Vs Code, then it runs into these issues.
Thanks anyhow 鉁岋笍
@DustinCampbell any thoughts on where we could track making this experience better for VS Code users?
@DustinCampbell any thoughts on where we could track making this experience better for VS Code users?
I think this is primarily a debugging question, yes? Including @gregg-miskelly in case he has any ideas.
@gregg-miskelly any thoughts? I'm going to close this issue here now but if there is a followup for the debugger, we can open an issue in the right repo.
@foo-baar if you hit stop debugging it works fine.
@foo-baar does David's suggestion work for you?
If not - does the process you are debugging get killed when you stop debugging? (diff the process list before and after)
If the process you are debugging gets killed - does your process spawn child processes?
@gregg-miskelly Well the thing is process never got killed by any vscode commands, I did it manually every time from terminal.
@foo-baar Thanks. In that case can you file a bug at https://github.com/omnisharp/omnisharp-vscode/issues and we can see why you are running into this problem.
Just close it the vscode and open it again.
This same thing happened to me. I went into inspect mode at http://localhost:5000 and went into the Application tab, and clicked Clear Site Data at the bottom. Hope this works for you.
So silly that I am, I commanded "killall" in my ssh terminal , and now I have to reset all. The issues raised here kind of helpful tho..
I had to kill all processes on the port, see this link.
This currently happens to me all the time as well, with a fresh install of dotnet. The project is here:
https://github.com/jeffnyman/testing-aspnet-core
Running dotnet run works just fine with this project on Windows, not at all on Mac (either Sierra, High Sierra or Mojave).
It initially tells me port 5000 is in use. It's not; I've checked. But I did run the kill steps on anything on the port as provided by seba-i. I then added the following line to Startup.cs:
.UseUrls("http://*:5001")
When I do that, then it tells me port 5001 is already in use. I realize the issue is closed but a lot of people are going to probably end up here as they experiment.
run lsof -ion Mac. That will tell you what ports are opened and what process holds them.
I got it to work again when I uninstalled "Visual Studio Build Tools 2017 (2)". I had the same problem where TCPView didn't even list the process using that specific port, I tried everything.
Why I tried to uninstall stuff was because my applications were able to start in safe mode (Windows 10). It made me think that something takes up the ports as soon as I log in.
Just close it the vscode and open it again.
Same for Visual Studio.
Just close it the vscode and open it again.
This one worked for me :) thx
You need just off or kill all network adapters and run it again - and all will be good.
asp.net core 3.0 on CentOS7
error : Failed to bind to address http://127.0.0.1:5000: address already in use.
Here is what I did. After changing applicationUrl from "https://localhost:5001;http://localhost:5000" to "https://localhost:4001;http://localhost:4000", the application output told me that
"The ASP.NET Core developer certificate is in an invalid state. To fix this issue, run the following commands 'dotnet dev-certs https --clean' and 'dotnet dev-certs https' to remove all existing ASP.NET Core development certificates and create a new untrusted developer certificate. On macOS or Windows, use 'dotnet dev-certs https --trust' to trust the new certificate."
I run 'dotnet dev-certs https --trust' and put in my computer's password fixed the issue.
while running the dotnet run if you stop the server using ctr + z then it _Ctrl+z_ sends the SIGTSTP (Signal Tty SToP) signal to the foreground job but don't actually stop the running kestrel server, so you have to mannualy end the process of the kestrel server.
SOLLUTION Only use ctr + c to stop the kestrel server, actually its even displayed on the shell while you run dotnet run.
To mannually kill the kestrel server use this command to see the running process and it pid on the port 5000
sudo lsof -iTCP -sTCP:LISTEN -P | grep :5000
then kill it with
sudo kill -9 PID
Hey guys i'm still having this problem actually... not sure why is this closed. Should we stop dotnet application manually everytime? I ran it with dotnet cli and its still happening
So here is the solution, if you are working on linux
while running the dotnet run if you stop the server using ctr + z then it _Ctrl+z_ sends the SIGTSTP (Signal Tty SToP) signal to the foreground job but don't actually stop the running kestrel server, so you have to mannualy end the process of the kestrel server.
SOLLUTION Only use ctr + c to stop the kestrel server, actually its even displayed on the shell while you run dotnet run.To mannually kill the kestrel server use this command to see the running process and it pid on the port 5000
sudo lsof -iTCP -sTCP:LISTEN -P | grep :5000
then kill it with
sudo kill -9 PID
Thanky you! worked for me.
I know this is already closed but wanted to add my experience with this issue. I was having the same error. I had originally used ctr + c to shut down the server. And when I tried to use dotnet run again that is when I got the error. I found I needed to manually pause and stop the application within the editor window, then retry the dotnet run.
Most helpful comment
@wfurt: I try with

lsof -i:5000it shows occupied by dotnet, so I kill it manually and then continue.