Skip to content

Commit

Permalink
Lock buffer when adding metrics (#4514)
Browse files Browse the repository at this point in the history
This function is not thread-safe but is currently used by multiple
goroutines in RunningOutput
  • Loading branch information
danielnelson authored Aug 7, 2018
1 parent 4dfb80d commit feb75d4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ func (b *Buffer) Len() int {

// Add adds metrics to the buffer.
func (b *Buffer) Add(metrics ...telegraf.Metric) {
b.mu.Lock()
for i, _ := range metrics {
MetricsWritten.Incr(1)
select {
case b.buf <- metrics[i]:
default:
b.mu.Lock()
MetricsDropped.Incr(1)
<-b.buf
b.buf <- metrics[i]
b.mu.Unlock()
}
}
b.mu.Unlock()
}

// Batch returns a batch of metrics of size batchSize.
Expand Down

0 comments on commit feb75d4

Please sign in to comment.