Skip to content

Commit

Permalink
fix: unexpected signal kill on some linux releases
Browse files Browse the repository at this point in the history
  • Loading branch information
r3inbowari committed Sep 10, 2023
1 parent df44d44 commit 6819a80
Showing 1 changed file with 13 additions and 11 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

0 comments on commit 6819a80

Please sign in to comment.