Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Write from being called concurrently #3011

Merged
merged 1 commit into from
Jul 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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