"code listen permission denied 127.0.0.1:1807"

Hey, I think I found the problem.

It took a bit of digging but I found this post on SuperUser:

where the commenter said:

In my case the error appears because the port used belong to reserved ports for Hyper-V.

This port range changes when I restart my computer, so sometimes I get the error sometimes no.
To check reserved ports by windows you can use(cmd/powershell):

netsh interface ipv4 show excludedportrange protocol=tcp

The issue is described in: Too many reserved port for Hyper-V · Issue #5514 · microsoft/WSL · GitHub

The port 1807 ended up being in a “reserved port range” for Hyper-V (on my system, 1741-1840 was reserved)

netsh interface ipv4 show excludedportrange protocol=tcp

Protocol tcp Port Exclusion Ranges

Start Port    End Port
----------    --------
...
      1741        1840

I changed the reserved port range as per the workaround in Unable to bind ports: Docker-for-Windows & Hyper-V excluding but not using important port ranges · Issue #3171 · docker/for-win · GitHub

netsh int ipv4 set dynamic tcp start=49152 num=16384

and rebooted.

It looks like this was sufficient to fix the issue.

I’m amazed that Hyper-V would just hold on to such low port numbers for itself.

1 Like