Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unexpected signal kill on some linux releases #150

Merged
merged 2 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions speedtest/data_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ func (f *funcGroup) Start(cancel context.CancelFunc, mainRequestHandlerIndex int
dbg.Printf("auxN: %d\n", auxN)
wg := sync.WaitGroup{}
f.manager.running = true
ticker := f.manager.rateCapture()
stopCapture := f.manager.rateCapture()
time.AfterFunc(f.manager.captureTime, func() {
ticker.Stop()
stopCapture <- true
close(stopCapture)
f.manager.running = false
cancel()
dbg.Println("FuncGroup: Stop")
Expand Down Expand Up @@ -220,15 +221,16 @@ func (f *funcGroup) Start(cancel context.CancelFunc, mainRequestHandlerIndex int
wg.Wait()
}

func (dm *DataManager) rateCapture() *time.Ticker {
func (dm *DataManager) rateCapture() chan bool {
ticker := time.NewTicker(dm.rateCaptureFrequency)
oldTotalDownload := dm.totalDownload
oldTotalUpload := dm.totalUpload
go func() {
loop:
stopCapture := make(chan bool)
go func(t *time.Ticker) {
defer t.Stop()
for {
select {
case <-ticker.C:
case <-t.C:
newTotalDownload := dm.totalDownload
newTotalUpload := dm.totalUpload
deltaDownload := newTotalDownload - oldTotalDownload
Expand All @@ -241,14 +243,14 @@ func (dm *DataManager) rateCapture() *time.Ticker {
if deltaUpload != 0 {
dm.UploadRateSequence = append(dm.UploadRateSequence, deltaUpload)
}
default:
if !dm.running {
break loop
case stop := <-stopCapture:
if stop {
return
}
}
}
}()
return ticker
}(ticker)
return stopCapture
}

func (dm *DataManager) NewChunk() Chunk {
Expand Down
2 changes: 1 addition & 1 deletion speedtest/speedtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

var (
version = "1.6.5"
version = "1.6.6"
DefaultUserAgent = fmt.Sprintf("showwin/speedtest-go %s", version)
)

Expand Down