Skip to content
This repository has been archived by the owner on Feb 19, 2025. It is now read-only.

Commit

Permalink
Merge pull request #83 from davmatjo/master
Browse files Browse the repository at this point in the history
Fix data race with templates and sampling
  • Loading branch information
lspgn authored Jul 14, 2020
2 parents d081643 + ed5301d commit efa7272
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 efa7272

Please sign in to comment.