Skip to content

Commit

Permalink
Prevent Write from being called concurrently (#3011)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored Jul 12, 2017
1 parent f68bab1 commit 5d2c093
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/models/running_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models

import (
"log"
"sync"
"time"

"github.com/influxdata/telegraf"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5d2c093

Please sign in to comment.