Skip to content

Commit

Permalink
fix: unexpected signal kill on some linux releases (#150)
Browse files Browse the repository at this point in the history
* fix: unexpected signal kill on some linux releases

* Release v1.6.6
  • Loading branch information
r3inbowari authored Sep 10, 2023
1 parent df44d44 commit b621f7c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
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

0 comments on commit b621f7c

Please sign in to comment.