Unable to start Kestrel. System.IO.IOException: Failed to bind to address http://localhost:5000 on the IPv4 loopback interface: port already in use.
Steps to reproduce
1 - open VSCode
2 - Load the project with Code .
2 - run the project using Dotnet watch run
Expected behavior
to make the app available http://localhost:5000
Actual behavior
Unable to start Kestrel. System.IO.IOException: Failed to bind to address http://localhost:5000 on the IPv4 loopback interface: port already in use.
Environment data
dotnet --info output:
Unable to start Kestrel.
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 -48 EADDRINUSE address already in use) ---> Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -48 EADDRINUSE address already in use
at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.ThrowError(Int32 statusCode)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.tcp_getsockname(UvTcpHandle handle, SockAddr& addr, Int32& namelen)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.GetSockIPEndPoint()
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerPrimary.CreateListenSocket()
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.<StartAsync>b__8_0(Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary.<StartAsync>d__12.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine.CreateServer(ServerAddress address)
at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication`1 application)
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication`1 application)
Unhandled Exception: 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 -48 EADDRINUSEaddress already in use) ---> Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -48 EADDRINUSE address already in use
at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.ThrowError(Int32 statusCode)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.tcp_getsockname(UvTcpHandle handle, SockAddr& addr, Int32& namelen)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.GetSockIPEndPoint()
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerPrimary.CreateListenSocket()
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.<StartAsync>b__8_0(Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary.<StartAsync>d__12.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine.CreateServer(ServerAddress address)
at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication`1 application)
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication`1 application)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.Start()
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host, CancellationToken token, String shutdownMessage)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
at Welocate.Program.Main(String[] args) in /Users/admin/welocate/Program.cs:line 20
watch : Exited with error code 134
watch : Waiting for a file to change before restarting dotnet...
The port is in use... You should be able to use netstat -a to see that.
ok, thanks.
For others having the same issue, here is the steps:
on terminal on MAC:
1 - soft -t -I :portNumber
process ID will be display (in case the port is in use ) ex: 10872
2 - kill -9 10872 (to kill the process)
I'm getting the following error on VS Code 1.24.1
Exception has occurred: CLR/System.IO.IOException An unhandled exception of type 'System.IO.IOException' occurred in System.Private.CoreLib.dll: 'Failed to bind to address https://127.0.0.1:5001: address already in use.' Inner exceptions found, see $exception in variables window for more details. Innermost exception System.Net.Sockets.SocketException : Address already in use at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName) at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.Bind(EndPoint localEP)
I can't kill process 296 on macOS with
kill -9 PID (to kill the process)
ok, thanks.
For others having the same issue, here is the steps:
on terminal on MAC:
1 - soft -t -I :portNumber process ID will be display (in case the port is in use ) ex: 10872 2 - kill -9 10872 (to kill the process)
I still have the same issue Win 10??
Having issue still while runing win 10 vs2017 Failed to bind to http://[::]:80 (IPv6Any). Attempting to bind to http://0.0.0.0:80 instead. crit: Microsoft.AspNetCore.Server.Kestrel[0] Unable to start Kestrel. Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvException: Error -4092 EACCES permission denied
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
On Windows: I was getting this error in a .dotnet core react template application and this little change of port number helped: In launchSettings.json from: "applicationUrl": "https://localhost:5001;http://localhost:5000", to: "applicationUrl": "https://localhost:7580;http://localhost:5000",