You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- What is your OS?
Linux ubuntu 16.04
- What is your client version?
v2.1.0
Other information (e.g. detailed explanation, logs, related issues, suggestions on how to fix, etc):
When run statsItemSet init() will start several goroutines to run sis.samplingInSeconds() and sis.printAtMinutes().
The samplingInSeconds() func will write csListMinute
While printAtMinutes() func call computeStatsData() will read csListMinute
func (si *statsItem) printAtMinutes() {
ss := computeStatsData(si.csListMinute)
rlog.Info("Stats In One Minute, SUM: %d TPS: AVGPT: %.2f", map[string]interface{}{
"statsName": si.statsName,
"statsKey": si.statsKey,
"SUM": ss.sum,
"TPS": fmt.Sprintf("%.2f", ss.tps),
"AVGPT": ss.avgpt,
})
}
var csListLock sync.Mutex
func computeStatsData(csList *list.List) statsSnapshot {
csListLock.Lock()
defer csListLock.Unlock()
tps, avgpt, sum := 0.0, 0.0, int64(0)
if csList.Len() > 0 {
first := csList.Front().Value.(callSnapshot)
last := csList.Back().Value.(callSnapshot)
sum = last.value - first.value
tps = float64(sum*1000.0) / float64(last.timestamp-first.timestamp)
timesDiff := last.time - first.time
if timesDiff > 0 {
avgpt = float64(sum*1.0) / float64(timesDiff)
}
}
return statsSnapshot{
tps: tps,
avgpt: avgpt,
sum: sum,
}
}
In samplingInSeconds() use csListMinuteLock while computeStatsData() use a global Mutex to lock. So read and write in different goroutine will cause DATA RACE.
The text was updated successfully, but these errors were encountered:
- What did you do (The steps to reproduce)?
Run the following test with
go test -race
The DATA RACE will print on terminal
- What did you expect to see?
Run the executable file generated by
go build -race
won't cause DATA RACE- What did you see instead?
See the DATA RACE
Please tell us about your environment:
Other information (e.g. detailed explanation, logs, related issues, suggestions on how to fix, etc):
When run statsItemSet
init()
will start several goroutines to runsis.samplingInSeconds()
andsis.printAtMinutes()
.The
samplingInSeconds()
func will writecsListMinute
While
printAtMinutes()
func callcomputeStatsData()
will readcsListMinute
In
samplingInSeconds()
usecsListMinuteLock
whilecomputeStatsData()
use a global Mutex to lock. So read and write in different goroutine will cause DATA RACE.The text was updated successfully, but these errors were encountered: