core icon indicating copy to clipboard operation
core copied to clipboard

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.

Open foo-baar opened this issue 9 years ago • 46 comments

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 👍

foo-baar avatar Sep 07 '17 08:09 foo-baar

How did you run the application?

davidfowl avatar Sep 07 '17 08:09 davidfowl

@davidfowl hey, using vscode: 'Start Debugging' command, and stopped the same way: Ctrl + C o 'Stop Debugging'

foo-baar avatar Sep 07 '17 08:09 foo-baar

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 avatar Sep 07 '17 10:09 hugobritobh

@hugobritobh I don't think your understood the issues: Port has not been released by Kestrel, irrespective of whichever one you use.

foo-baar avatar Sep 07 '17 12:09 foo-baar

@Eilon

Petermarcu avatar Sep 07 '17 15:09 Petermarcu

Did you check with netstat -an| grep 5000 what state the port is in @foo-baar

wfurt avatar Sep 07 '17 17:09 wfurt

@wfurt: I try with lsof -i:5000 it shows occupied by dotnet, so I kill it manually and then continue. screen shot 2017-09-08 at 10 51 30 am

foo-baar avatar Sep 08 '17 05:09 foo-baar

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.

wfurt avatar Sep 08 '17 06:09 wfurt

It's likely something to do with how the process is being launched. dotnet run doesn't forward control + c to the child process.

davidfowl avatar Sep 08 '17 06:09 davidfowl

@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 ✌️

foo-baar avatar Sep 08 '17 06:09 foo-baar

Ah, sounds like the old Ctrl-C is killing parent but not dotnet children: https://github.com/dotnet/cli/issues/7426

omajid avatar Sep 08 '17 17:09 omajid

@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.

foo-baar avatar Sep 08 '17 18:09 foo-baar

Is there anything else that needs to be done here or can we close this issue out?

Petermarcu avatar Oct 07 '17 17:10 Petermarcu

@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 ✌️

foo-baar avatar Oct 08 '17 04:10 foo-baar

@DustinCampbell any thoughts on where we could track making this experience better for VS Code users?

Petermarcu avatar Oct 09 '17 01:10 Petermarcu

@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.

DustinCampbell avatar Oct 09 '17 17:10 DustinCampbell

@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.

Petermarcu avatar Oct 12 '17 06:10 Petermarcu

@foo-baar if you hit stop debugging it works fine.

davidfowl avatar Oct 12 '17 06:10 davidfowl

@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 avatar Oct 12 '17 14:10 gregg-miskelly

@gregg-miskelly Well the thing is process never got killed by any vscode commands, I did it manually every time from terminal.

foo-baar avatar Oct 12 '17 20:10 foo-baar