Skip to content

Commit

Permalink
Fix data race with templates and sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
davmatjo authored Jul 14, 2020
1 parent d081643 commit ed5301d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions utils/netflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,25 @@ func (s *StateNetFlow) DecodeFlow(msg interface{}) error {

s.templateslock.RLock()
templates, ok := s.templates[key]
s.templateslock.RUnlock()
if !ok {
templates = &TemplateSystem{
templates: netflow.CreateTemplateSystem(),
key: key,
}
s.templateslock.Lock()
s.templates[key] = templates
s.templateslock.Unlock()
}
s.templateslock.RUnlock()
s.samplinglock.RLock()
sampling, ok := s.sampling[key]
s.samplinglock.RUnlock()
if !ok {
sampling = producer.CreateSamplingSystem()
s.samplinglock.Lock()
s.sampling[key] = sampling
s.samplinglock.Unlock()
}
s.samplinglock.RUnlock()

ts := uint64(time.Now().UTC().Unix())
if pkt.SetTime {
Expand Down

0 comments on commit ed5301d

Please sign in to comment.