Prevent Write from being called concurrently (#3011)

This commit is contained in:
Daniel Nelson 2017-07-12 12:03:23 -07:00 committed by GitHub
parent d21a9316bd
commit c5d49d1863
1 changed files with 6 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package models
import ( import (
"log" "log"
"sync"
"time" "time"
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
@ -34,6 +35,9 @@ type RunningOutput struct {
metrics *buffer.Buffer metrics *buffer.Buffer
failMetrics *buffer.Buffer failMetrics *buffer.Buffer
// Guards against concurrent calls to the Output as described in #3009
sync.Mutex
} }
func NewRunningOutput( func NewRunningOutput(
@ -169,6 +173,8 @@ func (ro *RunningOutput) write(metrics []telegraf.Metric) error {
if nMetrics == 0 { if nMetrics == 0 {
return nil return nil
} }
ro.Lock()
defer ro.Unlock()
start := time.Now() start := time.Now()
err := ro.Output.Write(metrics) err := ro.Output.Write(metrics)
elapsed := time.Since(start) elapsed := time.Since(start)