bzznectar / nectar

Decentralised tokenomics layer of the Nectar for Swarm network
https://docs.bzznectar.org/docs/
7 stars 1 forks source link

Network speed test fails after first run #4

Open ldeffenb opened 2 years ago

ldeffenb commented 2 years ago

When first running the nectar client, it successfully tests my network bandwidth. However, the retest that is supposed to occur at the top of every hour (minute==0) fails with the following logs:

can't not find server,please check net

time="2021-12-07T10:00:00-05:00" level=info msg="[retrying after error:]"
timeout speed 0!
can't not find server,please check net

time="2021-12-07T10:00:01-05:00" level=info msg="[retrying after error:]"
timeout speed 0!
can't not find server,please check net

time="2021-12-07T10:00:03-05:00" level=info msg="[retrying after error:]"
timeout speed 0!
can't not find server,please check net

after 4 attempts, last error: timeout speed 0!

This results in the originally determined network bandwidth being used in every update which I'm pretty sure is not the intent.

ldeffenb commented 2 years ago

Note that both of the speed test URLs respond with valid-looking data from my network:

https://www.speedtest.net/speedtest-config.php https://www.speedtest.net/speedtest-servers.php

ldeffenb commented 2 years ago

I have tracked it down to the fact that the Unmarshal call is returning zero servers on the second invocation, first being at startup which works and second being at the top (minute=0) of the next hour. Looking at the raw XML body when the next hour strikes.

https://github.com/bzznectar/nectar/blob/87ca581552f007b345d7c7cf08292f07bcf3681f/pkg/tools/speedtest.go#L185

ldeffenb commented 2 years ago

Nailed it! As I expected, although not really expected until things ramp up, it's not a good idea to have code that time-synchronizes access to some external resource. Given that speedtest is invoked within one second of the top of the hour (minute=0), this is not surprising:

GetServers: Got <html><head><title>Too Many Requests</title></head><body><h1>429 Error - Too Many Requests</h1><p>Our systems are overloaded. Please retry your request at a different time.</p></body></html>
GetServers: Unmarshal gave 0 servers

No wonder the Unmarshal came up with zero servers for the subsequent speed tests!