diff --git a/speedtest/data_manager.go b/speedtest/data_manager.go index bbf8357..7ae2a48 100644 --- a/speedtest/data_manager.go +++ b/speedtest/data_manager.go @@ -248,7 +248,10 @@ func (td *TestDirection) Start(cancel context.CancelFunc, mainRequestHandlerInde go func() { defer wg.Done() for { - if !td.manager.running { + td.manager.runningRW.RLock() + running := td.manager.running + td.manager.runningRW.RUnlock() + if !running { return } td.fns[t]() diff --git a/speedtest/server.go b/speedtest/server.go index fd56160..c48524f 100644 --- a/speedtest/server.go +++ b/speedtest/server.go @@ -293,11 +293,11 @@ func (s *Speedtest) FetchServerListContext(ctx context.Context) (Servers, error) var latency []int64 var errPing error if s.config.PingMode == TCP { - _, errPing = gs.TCPPing(pCtx, 1, time.Millisecond, nil) + latency, errPing = gs.TCPPing(pCtx, 1, time.Millisecond, nil) } else if s.config.PingMode == ICMP { - _, errPing = gs.ICMPPing(pCtx, 4*time.Second, 1, time.Millisecond, nil) + latency, errPing = gs.ICMPPing(pCtx, 4*time.Second, 1, time.Millisecond, nil) } else { - _, errPing = gs.HTTPPing(context.Background(), 1, time.Millisecond, nil) + latency, errPing = gs.HTTPPing(context.Background(), 1, time.Millisecond, nil) } if errPing != nil || len(latency) < 1 { gs.Latency = PingTimeout