Unable to start Kestrel - port 8000 already in use
See original GitHub issue- Version: ElectronNET.CLI Version: 5.22.12.0
<TargetFramework>netcoreapp2.2</TargetFramework>
...
➜ electron-v5 git:(master) ✗ node -v
v8.15.1
➜ electron-v5 git:(master) ✗ npm -v
6.4.1
- Target: Mac OSX
Steps to Reproduce:
- Follow readme to create basic application
- Run
electronize start
- Receive error:
➜ electron-v5 git:(master) ✗ electronize start
Start Electron Desktop Application...
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 49.16 ms for /Users/rosenbek/Desktop/csharp/electron-v5/electron-v5.csproj.
electron-v5 -> /Users/rosenbek/Desktop/csharp/electron-v5/bin/Debug/netcoreapp2.2/osx-x64/electron-v5.dll
electron-v5 -> /Users/rosenbek/Desktop/csharp/electron-v5/bin/Debug/netcoreapp2.2/osx-x64/electron-v5.Views.dll
electron-v5 -> /Users/rosenbek/Desktop/csharp/electron-v5/obj/Host/bin/
node_modules missing in: /Users/rosenbek/Desktop/csharp/electron-v5/obj/Host/node_modules
Start npm install...
up to date in 10.931s
ElectronHostHook handling started...
Invoke electron - in dir: /Users/rosenbek/Desktop/csharp/electron-v5/obj/Host/node_modules/.bin
Electron Socket IO Port: 8000
Electron Socket started on port 8000 at 127.0.0.1
ASP.NET Core Port: 8000
stdout: Use Electron Port: 8000
ASP.NET Core Application connected... global.electronsocket EKbRPQpPh_WrAD8AAAAA 2019-05-29T13:21:26.705Z
stdout: crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
System.IO.IOException: Failed to bind to address http://127.0.0.1:8000: address already in use. ---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use ---> 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)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransport.BindAsync()
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransport.BindAsync()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<>c__DisplayClass21_0`1.<<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.AddressesStrategy.BindAsync(AddressBindContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func`2 createBinding)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
After receiving the error, I can inspect the process and see that the only thing running on port 8000 is the Electron.NET app itself:
➜ electron-v5 git:(master) ✗ lsof -t -i :8000
4474
➜ electron-v5 git:(master) ✗ ps -p 4474
PID TTY TIME CMD
4474 ttys001 0:00.38 /Users/rosenbek/Desktop/csharp/electron-v5/obj/Host/node_modu
So it appears that somehow the app is detecting 8000 is open, and then another part of the process looks to use 8000 even though it isn’t open?
The only variable in this that makes me think it is potentially something nefarious is that I am on a work VPN. It appears that as long as I am connected to work VPN, Electron.NET misdiagnoses open ports.
Is there anything in the source obvious to you which might fail to detect open port properly? It seems to me like maybe Socket IO chooses to use 8000, and then ASP.NET tries to use it right after:
Electron Socket IO Port: 8000
Electron Socket started on port 8000 at 127.0.0.1
ASP.NET Core Port: 8000
stdout: Use Electron Port: 8000
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:19 (8 by maintainers)
Top Results From Across the Web
Unable to start Kestrel. System.IO.IOException: Failed to ...
In my case, I was able to work around this by changing the port Kestrel was using. Here are two options that worked...
Read more >Configure endpoints for the ASP.NET Core Kestrel web ...
Learn about configuring endpoints with Kestrel, ... port is in use by another service on either loopback interface, Kestrel fails to start.
Read more >System.IO.IOException: Failed to bind to address
Kestrel: Critical: Unable to start Kestrel. System.IO.IOException: Failed to bind to address https://127.0.0.1:5000: address already in use.
Read more >Run two ASP.NET Core applications at the same time
Per this message, another process is already using port 5000. This is obvious. But how can you learn which process is using the...
Read more >System.IO.IOException: Failed to bind to address http://127.0 ...
That mean the port 5000 is already in use by another application. Check if you have another application running that use that port....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Mh - You could check your local nuget cache folder and delete the package or bump up the version number from your local build. Maybe NuGet will try to use the “cached” version.
By the way, there are still plenty of native Electron features that are only for Mac. We have not implemented it yet because we do not have a Mac. If you want to tap into the missing APIs, the Electron.NET would greatly enrich. 😃
https://electronjs.org/docs/api (see the “for native macOS applications” parts in the description)