internet-equity / netrics

The network measurements scheduling framework
7 stars 3 forks source link

speed-ookla fails in systemd environment #48

Closed jesteria closed 1 year ago

jesteria commented 1 year ago

The speed-ookla measurement fails iff the environment variable HOME is unset. This is the case for the default Systemd unit configuration, (which does not provide such things by default).

This can be reproduced outside of Systemd, and outside of Netrics, with the Ookla speedtest binary itself:

$ env -u HOME speedtest --progress no --format json --accept-license            
terminate called after throwing an instance of 'std::logic_error'                                                                                                                             
  what():  basic_string::_M_construct null not valid                                                                                                                                          
Aborted (core dumped)                         

This is due to the speedtest attempting to record the user's acceptance of the license under their HOME directory. As it happens, the binary does correctly handle an empty HOME variable (and apparently skips this record):

$ env HOME="" speedtest --progress no --format json --accept-license            
{"type":"result","timestamp":"2023-05-05T03:11:30Z","ping":{"jitter":0.050,"latency":3.966,"low":3.865,"high":3.979},"download":{"bandwidth":46289446,"bytes":190701600,"elapsed":4109,"latenc
y":{"iqm":12.129,"low":5.948,"high":30.514,"jitter":0.937}},"upload":{"bandwidth":16368894,"bytes":126886536,"elapsed":7812,"latency":{"iqm":2.692,"low":2.259,"high":36.004,"jitter":0.855}},
"packetLoss":0,"isp":"AT&T Internet","interface":{"internalIp":"192.168.1.77","name":"eth0","macAddr":"DC:A6:32:EB:D6:DE","isVpn":false,"externalIp":"76.229.201.211"},"server":{"id":12187,"h
ost":"speedtest.chi1.nitelusa.net","port":8080,"name":"Nitel","location":"Chicago, IL","country":"United States","ip":"45.61.24.34"},"result":{"id":"1a3a70ed-d018-4ac7-8a13-1137cd8e4d6c","ur
l":"https://www.speedtest.net/result/c/1a3a70ed-d018-4ac7-8a13-1137cd8e4d6c","persisted":true}} 

However, a bug in the Ookla speedtest causes it to crash if the variable is entirely unset. This is never the case in typical use by a human; but, it is entirely to be expected of our use.


This could in theory be resolved at the level of the Systemd configuration, or at lower levels. For example:

Environment=HOME="" PATH="/opt/netrics/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

However, this is only the preoccupation of the Ookla speedtest, and special handling should be limited to it. Users and administrators of this software shouldn't be bothered with the consideration, either. As such, the speedtest binary might be invoked by speed-ookla with an environment empty but for HOME="". (There is no need for it to record license acceptance in those instances where HOME is set.)