Have you ever cloned a new project, ran:
npm run dev
or
docker compose up
only to be greeted with an error like:
Error: listen EADDRINUSE
or
bind: An attempt was made to access a socket in a way forbidden by its access permissions.
The strange part?
- Nothing appears to be using the port.
- Restarting the application doesn't help.
- Even changing to another port sometimes fails.
- The issue often starts after connecting to a VPN, enabling Docker Desktop, WSL2, or Hyper-V.
I recently ran into exactly this problem, and the fix was surprisingly simple.
Why Does This Happen?
On Windows, the Host Network Service (HNS) manages networking for technologies such as:
- Docker Desktop
- WSL2
- Hyper-V
- Windows Containers
- Some VPN software
Sometimes HNS reserves or holds ports even after applications have exited, preventing new processes from binding to them. This behavior has also been reported by developers using Docker, Hyper-V, and WSL networking.
As a result, Windows behaves as if the port is already occupied.
Symptoms
You may notice errors like:
EADDRINUSE
Address already in use
Only one usage of each socket address is normally permitted
or Docker errors related to port publishing.
This is especially common after:
- Connecting or disconnecting from a VPN
- Starting Docker Desktop
- Using WSL2
- Working with Hyper-V virtual machines
- Switching between networking environments
The Fix
Open PowerShell as Administrator and run:
net stop hns
If Windows asks whether dependent services should also be stopped:
The following services are dependent on the Host Network Service...
Do you want to continue? (Y/N)
Type:
Y
That's it.
In many cases, your application will immediately be able to bind to the port again.
If That Doesn't Work
If the issue persists, check whether Windows has reserved your port:
netsh interface ipv4 show excludedportrange protocol=tcp
If your desired port falls inside one of the excluded ranges, Windows has reserved it for networking components such as Hyper-V or HNS.
Why Restarting HNS Works
Stopping the Host Network Service forces Windows to rebuild its networking state and releases stale network resources.
It's much faster than:
- Restarting your computer
- Reinstalling Docker
- Reinstalling your VPN
- Spending an hour wondering why
localhost:3000suddenly stopped working
When Should You Use This?
This solution is worth trying if:
- Your development server suddenly won't start.
- Docker reports port binding failures.
- A port appears to be in use but nothing is listening on it.
- The issue began after using Docker Desktop, WSL2, Hyper-V, or a VPN.
Final Thoughts
The next time Windows insists that a port is already in use—even though every process says otherwise—don't immediately assume your application is broken.
Try:
net stop hns
It has saved me more than once, and hopefully it saves you some debugging time too.
If you've encountered other strange Windows networking issues, I'd love to hear how you solved them in the comments.
Top comments (0)