github-vet / github-vet/rangeloop-pointer-findings
AISphere/ffdl-cli: cmd/scaletest.go; 231 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [AISphere/ffdl-cli](https://www.github.com/AISphere/ffdl-cli) at [cmd/scaletest.go](https://github.com/AISphere/ffdl-cli/blob/28f2457ad77e38d04a3146000db5a29d5eaf4977/cmd/scaletest.go#L151-L381)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first
issue it finds, so please do not limit your consideration to the contents of the below message.
> range-loop variable epochIndex used in defer or goroutine at line 265
[Click here to see the code in its original context.](https://github.com/AISphere/ffdl-cli/blob/28f2457ad77e38d04a3146000db5a29d5eaf4977/cmd/scaletest.go#L151-L381)
Click here to show the 231 line(s) of Go which triggered the analyzer.
```go
for epochIndex, numberIterations := range scaleEpochs {
startThisEpoch := time.Now()
fmt.Printf("\n-----\nstarting epoch %d, launching %d concurrent instances\n",
epochIndex, numberIterations)
var trainingIDs []string
allLogLinesDone := true
allEmetricsDone := true
nLLTargetIterations := 0
if logsFollow {
nLLTargetIterations = numberIterations
allLogLinesDone = false
}
nEMTargetIterations := 0
if emetricsFollow {
nEMTargetIterations = numberIterations
allEmetricsDone = false
}
numLogLineTimingDoneChan := make(chan int, nLLTargetIterations)
numEMetricsTimingDoneChan := make(chan int, nEMTargetIterations)
var logLinesTimings= make([]*LogLinesTimings, 0)
var eMetricsTimings= make([]*EMetricsTimings, 0)
for i := 0; i < numberIterations; i++ {
//d := time.Now().Add(10 * time.Second)
//ctx, cancel := context.WithDeadline(context.Background(), d)
//defer cancel()
ctx := context.Background()
var resp *grpc_trainer_v2.CreateResponse
resp, err = dlaasGrpcClient.Client().CreateTrainingJob(ctx, createReq)
if err != nil {
fmt.Printf("Error:\n\t")
fmt.Println(err.Error())
fmt.Println("dlaasGrpcClient.Client().CreateTrainingJob(...) returned error. Giving up.")
}
if resp != nil {
trainingIDs = append(trainingIDs, resp.TrainingId)
if scaleTestVerbose {
fmt.Printf("Training job created. Training ID is %s\n", resp.TrainingId)
} else if !logsFollow && !emetricsFollow {
fmt.Print("T")
}
logLineTimingDone := make(chan int, 0)
eMetricsTimingDone := make(chan int, 0)
logLineTimingChan := make(chan *LogLinesTimings)
eMetricsTimingChan := make(chan *EMetricsTimings)
logLinesDone := false
emetricsDone := false
if logsFollow {
go func() {
logLinesTimings = fetchLogLines(resp.TrainingId, true,
logLinesTimings, logLineTimingChan)
logLineTimingDone <- 1
}()
} else {
logLinesDone = true
}
if emetricsFollow {
go func() {
eMetricsTimings = fetchEMetrics(resp.TrainingId, true,
eMetricsTimings, eMetricsTimingChan)
eMetricsTimingDone <- 1
}()
} else {
emetricsDone = true
}
go func() {
if didPrintColumnHeaders == false {
didPrintColumnHeaders = true
fmt.Printf("\n=============\n")
fmt.Printf("%5s\t%3s\t%19s\t%9s\t%3s\t%5s\t%5s\n",
"Epoch", "Typ", "TID", "LLQRsp", "NRcv", "LLSnd", "FLSnd")
}
for ; !logLinesDone || !emetricsDone; {
select {
case isDone := <-logLineTimingDone:
if isDone == 1 {
if scaleTestVerbose {
fmt.Printf("Marking done LL: %s\n", resp.TrainingId)
}
if emetricsDone {
deleteJob(resp.TrainingId, userID)
}
numLogLineTimingDoneChan <- 1
logLinesDone = true
}
case isDone := <-eMetricsTimingDone:
if isDone == 1 {
if scaleTestVerbose {
fmt.Printf("Marking done EM: %s\n", resp.TrainingId)
}
if logLinesDone {
deleteJob(resp.TrainingId, userID)
}
numEMetricsTimingDoneChan <- 1
emetricsDone = true
}
case rec := <-logLineTimingChan:
fmt.Printf("%5d\t%3s\t%19s\t%09.6f\t%3d\t%05.03f\t%05.03f\n",
epochIndex, "LL", rec.trainingID, rec.secondsForCall, rec.nLinesInResp,
rec.firstLineTime, rec.lastLineTime)
case rec := <-eMetricsTimingChan:
fmt.Printf("%5d\t%3s\t%19s\t%09.6f\t%3d\t%05.03f\t%05.03f\n",
epochIndex, "EM", rec.trainingID, rec.secondsForCall, rec.nLinesInResp,
rec.firstLineTime, rec.lastLineTime)
case <-time.After(20 * time.Minute):
fmt.Print("Time out waiting for the logs and/or emetrics (training level)!\n")
logLinesDone = true
emetricsDone = true
deleteJob(resp.TrainingId, userID)
numEMetricsTimingDoneChan <- 1
break
}
}
}()
} else {
if logsFollow {
nLLTargetIterations--
}
if emetricsFollow {
nEMTargetIterations--
}
}
}
if scaleTestVerbose {
fmt.Print("Waiting for all loops to complete!\n")
}
for ; !allLogLinesDone || !allEmetricsDone; {
select {
case <-numLogLineTimingDoneChan:
nLLTargetIterations -= 1
if scaleTestVerbose {
fmt.Printf("A job in epoch LL %d is done, still running instances: %d\n",
epochIndex, nLLTargetIterations)
}
if nLLTargetIterations <= 0 {
allLogLinesDone = true
}
case <-numEMetricsTimingDoneChan:
nEMTargetIterations -= 1
if scaleTestVerbose {
fmt.Printf("A job in epoch EM %d is done, still running instances: %d\n",
epochIndex, nEMTargetIterations)
}
if nEMTargetIterations <= 0 {
allEmetricsDone = true
}
case <-time.After(40 * time.Minute):
fmt.Printf("Time out waiting for the logs and/or emetrics (epoch level): %d left\n",
nEMTargetIterations)
allLogLinesDone = true
allEmetricsDone = true
break
}
}
averageLLTimes := AverageTimings{
numberConcurrentJobs: numberIterations,
secondsForQueryResponse: 0.0,
secondsSinceSend: 0.0,
}
averageEMTimes := AverageTimings{
numberConcurrentJobs: numberIterations,
secondsForQueryResponse: 0.0,
secondsSinceSend: 0.0,
}
if logLinesTimings != nil && len(logLinesTimings) > 0 {
for _, rec := range logLinesTimings {
averageLLTimes.secondsForQueryResponse += rec.secondsForCall
averageLLTimes.secondsSinceSend += rec.firstLineTime
averageLLTimes.secondsSinceSend += rec.lastLineTime
}
averageLLTimes.secondsForQueryResponse =
averageLLTimes.secondsForQueryResponse / float64(len(logLinesTimings))
averageLLTimes.secondsSinceSend = averageLLTimes.secondsSinceSend / float64(len(logLinesTimings)*2)
}
if eMetricsTimings != nil && len(eMetricsTimings) > 0 {
for _, rec := range eMetricsTimings {
averageEMTimes.secondsForQueryResponse += rec.secondsForCall
averageEMTimes.secondsSinceSend += rec.firstLineTime
averageEMTimes.secondsSinceSend += rec.lastLineTime
}
averageEMTimes.secondsForQueryResponse =
averageEMTimes.secondsForQueryResponse / float64(len(eMetricsTimings))
averageEMTimes.secondsSinceSend = averageEMTimes.secondsSinceSend / float64(len(eMetricsTimings)*2)
}
averagesLLList[epochIndex] = &averageLLTimes
averagesEMList[epochIndex] = &averageEMTimes
fmt.Print("\n#####\n")
fmt.Printf("Averages for Epoch %d (%d iterations) results:\n", epochIndex, numberIterations)
fmt.Printf("\n%5s\t%9s\t%9s\n", "NConc", "LLQRsp", "EMQRsp")
fmt.Printf("%5d\t%09.6f\t%09.6f\n",
numberIterations,
averagesLLList[epochIndex].secondsForQueryResponse,
averagesEMList[epochIndex].secondsForQueryResponse)
fmt.Printf("\n%5s\t%9s\t%9s\n", "NConc", "LLSnd", "EMSnd")
fmt.Printf("%5d\t%09.6f\t%09.6f\n",
numberIterations,
averagesLLList[epochIndex].secondsSinceSend,
averagesEMList[epochIndex].secondsSinceSend)
fmt.Print("\n#####\n")
elapsedThisEpoch := time.Since(startThisEpoch)
if scaleTestVerbose {
fmt.Printf("\nDone with Epoch %d, %d jobs, Total time: %4.2f minutes\n",
epochIndex, numberIterations, elapsedThisEpoch.Minutes())
}
time.Sleep(5*time.Second)
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: 28f2457ad77e38d04a3146000db5a29d5eaf4977
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.