trezor / trezord-go

:smiling_imp: Trezor Communication Daemon (written in Go)
GNU Lesser General Public License v3.0
244 stars 146 forks source link

trezord silently failing to start if port 21325 is in excluded range #201

Closed langerhans closed 3 years ago

langerhans commented 3 years ago

Hi, I noticed today that I can't run trezord and thus the wallet anymore. This started happening after I installed Windows 10 20H2 (10.0.19042.610). It appears that something is now reserving port ranges throughout the system and unlucky for me, one of the ranges includes port 21325. trezord won't start because of this and there is no indication anywhere aside from the log:

2020/11/05 17:30:05 https: listen tcp 127.0.0.1:21325: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

You can query the excluded port ranges in windows like this:

netsh interface ipv4 show excludedportrange protocol=tcp

Startport      Endport
----------    --------
      1571        1670
      1671        1770
      1771        1870
      1871        1970
      2171        2270
     21221       21320
     21321       21420
     50000       50059     *

I can't fully confirm this was actually caused by the update cause there is no indication as to what reserved those ports. It might be desirable to alert the user of such an issue. Trezor Suite will currently just "gather information".

[EDIT: I removed the mentions of Hyper-V from the report as I noticed that I did not in fact enable it] [One more Edit: Might have to do with WSL2]

prusnak commented 3 years ago

Can you please try to find out what exactly is causing this?

langerhans commented 3 years ago

So this might be random, but disabling WSL2 and Hyper-V by

Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

removed the reserved port ranges reported above. That also fixed trezord. I then re-enabled WSL2 and the ports are now reserved in a different range. At least that is my guess due to it being 7x 100 ports again:

Startport      Endport
----------    --------
     50000       50059     *
     50241       50340
     50341       50440
     50441       50540
     50541       50640
     50641       50740
     50741       50840
     50944       51043

So I guess this was just me being unlucky. Still, a message about this blocked port somewhere might be desirable.

langerhans commented 3 years ago

Oh, just rebooted again. The ports are only reserved once you boot WSL2. Before they will not be. And the ranges change with every launch of WSL2. So simply rebooting should fix this issue :) Note that just stopping the WSL2 VM does not free the ports.