From d230a1b62973f1f767c786091b287419fc4630c1 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 21 Jul 2020 11:44:01 -0700 Subject: [PATCH] Fix Data Race in Metrics --- server/metrics/metrics.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/metrics/metrics.go b/server/metrics/metrics.go index abbcac4..805515a 100644 --- a/server/metrics/metrics.go +++ b/server/metrics/metrics.go @@ -151,11 +151,13 @@ func (mh *monitorHistory) Months() []float64 { } func (mh *monitorHistory) Report(w *bufio.Writer) { + mh.lock.Lock() fmt.Fprintln(w, "Minutes:", reportLine(mh.monitorType, mh.perMinutePerHour[:])) fmt.Fprintln(w, "Hours: ", reportLine(mh.monitorType, mh.perHourForDay[:])) fmt.Fprintln(w, "Days: ", reportLine(mh.monitorType, mh.perDayForWeek[:])) fmt.Fprintln(w, "Weeks: ", reportLine(mh.monitorType, mh.perWeekForMonth[:])) fmt.Fprintln(w, "Months: ", reportLine(mh.monitorType, mh.perMonthForYear[:])) + mh.lock.Unlock() } func reportLine(t MonitorType, array []float64) string {