Unable to start kestrel. System.IO.IOException: Failed to bind to address https://127.0.0.1:5001: address already in use.
I'm trying to run my project (that was working locally) on an archlinux VPS with .net core 3.1 installed, but I'm getting address in use errors. I've checked port usage and they were not in use.. ports 5001 and 5000 were also not released after this happened and I had to kill the process manually
crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
System.IO.IOException: Failed to bind to address https://127.0.0.1:5001: address already in use.
---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use
---> System.Net.Sockets.SocketException (98): Address already in use
at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
output of sudo netstat -tunlp before running the app
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:5355 0.0.0.0:* LISTEN 408/systemd-resolve
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 408/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1155/sshd
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 457/postgres
tcp6 0 0 :::3306 :::* LISTEN 478/mysqld
tcp6 0 0 :::5355 :::* LISTEN 408/systemd-resolve
tcp6 0 0 :::22 :::* LISTEN 1155/sshd
tcp6 0 0 :::3000 :::* LISTEN 566/gitea
tcp6 0 0 ::1:5432 :::* LISTEN 457/postgres
udp 0 0 0.0.0.0:5355 0.0.0.0:* 408/systemd-resolve
udp 0 0 127.0.0.53:53 0.0.0.0:* 408/systemd-resolve
udp6 0 0 :::5355 :::* 408/systemd-resolve ```
none of the suggestions in #948 and #2001 helped..
there was another dotnet app running in a docker container that autostarts 4-5 seconds after I killed it.. closing.
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. And use only 5000 port inside launchSettings.json in kestrel (one with the project name) profile
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
This is a problem we have a main domain (abc.com) running and then try to run subdomain.abc.com. I noticed you can't run BOTH at the same time, or even back to back (on Linux) with a browser without manually intervening and killing the process. I have in my Program.cs
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>()
.UseUrls("http://localhost:5001")
;
});
Should the UseUrls be taken out? Does kestrel know to listen automatically on 5001?
Is there a way to handle this without manual intervention?
It is also a constant problem if you try to start 2 UNITS that start a dotnet process for a different app and do
sudo systemctl status myfirst.service <--- works sudo systemctl status mysecond.service <------ FAILS with the error
I need both running
there was another dotnet app running in a docker container that autostarts 4-5 seconds after I killed it.. closing.
Hi I am experiencing the same Issue on mine, I am running Linux centos server 7 , using core 3.1. can you give more details of how you manage to see the process as when I run mine it just not there.
Here it is in more detail.
Start:
System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use.
---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use
---> System.Net.Sockets.SocketException (98): 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)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<>c__DisplayClass21_01.<<StartAsync>g__OnBind|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context)
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.LocalhostListenOptions.BindAsync(AddressBindContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.EndpointsStrategy.BindAsync(AddressBindContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func2 createBinding)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
Failed to bind to address http://127.0.0.1:5000: address already in use.
End:
@samgithub @santiagofigueroa How did you solve the problem?
I am having the same issue. 2 dotnet applications on my Ubuntu, binding on different ports.
The second process fails with the "address already in use" error, no matter what port i use for the second process
@lbphp Hi used these commands and it helped. 1st sudo lsof -iTCP -sTCP:LISTEN -P | grep :5000
then kill it with
sudo kill -9 PID
Then restart your services as usual and should be fine.
Did this topic only happen after you killed the service previously?
I have the very same case but it happens at startup of the system where the linux autmatically starts the .netcore kestrel hosting...