lockers

Fixing failed port bindings – Junior Developer Handbook

Sometimes your application won’t start because it tries to bind to a port that’s already in use. IIS Express for example shows you this error notification:

The specified port is in use

Port X is already being used by another application.

Recommendations

  1. Try switching to port other than X and higher than 1024.
  2. Stop the application that is using port X.

Fix 1 – Find the application using the port

Open an administrative PowerShell and issue this command

Get-Process -Id (Get-NetTCPConnection -LocalPort <Your Port Here>).OwningProcess

This will show you an error if no application is using the port or the process using the port. To kill the process, pipe the output from the command above into Stop-Process like this:

Get-Process -Id (Get-NetTCPConnection -LocalPort 62216).OwningProcess | Stop-Process

Fix 2 – The desired port may be reserved

Hyper-V and other components reserve port space for their own use. Even when they are unused at the moment, trying to bind to them will not work. To find port ranges that are reserved use this command:

netsh interface ipv4 show excludedportrange protocol=tcp

If your port is within one of these ranges, you’ll need to select a different port which is not part of any of those ranges.

Fix 3 – If all else fails

Reboot your machine.

Photo by moren hsu on Unsplash