Skip to content

Commit

Permalink
fix(api): data race in value running
Browse files Browse the repository at this point in the history
  • Loading branch information
r3inbowari committed Jul 13, 2024
1 parent 8beddc9 commit dedf56c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion speedtest/data_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
Expand Down
6 changes: 3 additions & 3 deletions speedtest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dedf56c

Please sign in to comment.