Port localhost:5000 not released causing error System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use.
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
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.