From 5d2c093105170f0ccf2ca72b6fc742b2d02b07a8 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Wed, 12 Jul 2017 12:03:23 -0700 Subject: [PATCH] Prevent Write from being called concurrently (#3011) --- internal/models/running_output.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/models/running_output.go b/internal/models/running_output.go index 61f26add1..335fb792f 100644 --- a/internal/models/running_output.go +++ b/internal/models/running_output.go @@ -2,6 +2,7 @@ package models import ( "log" + "sync" "time" "github.com/influxdata/telegraf" @@ -34,6 +35,9 @@ type RunningOutput struct { metrics *buffer.Buffer failMetrics *buffer.Buffer + + // Guards against concurrent calls to the Output as described in #3009 + sync.Mutex } func NewRunningOutput( @@ -169,6 +173,8 @@ func (ro *RunningOutput) write(metrics []telegraf.Metric) error { if nMetrics == 0 { return nil } + ro.Lock() + defer ro.Unlock() start := time.Now() err := ro.Output.Write(metrics) elapsed := time.Since(start)