phaag / go-nfdump

go-nfdump: A Go module to read and process nfdump files
BSD 2-Clause "Simplified" License
7 stars 1 forks source link

Data Races detected after latest sampler extesion #6

Closed gabrielmocan closed 1 year ago

gabrielmocan commented 1 year ago

Hi Pete, my tests are failing due to data races after sunday's commits. Log below:

❯ go run -race . nfdumpNative
INFO: 2023/02/26 21:40:49 escrevendo mmdb em ./tests/mmdb/asn.mmdb (603093 entradas)
INFO: 2023/02/26 21:41:23 MMDB inicializado com sucesso
==================
WARNING: DATA RACE
Write at 0x00c0029641f0 by goroutine 20:
  github.com/phaag/go-nfdump.(*NfFile).addExporterStat()
      go-nfdump@v0.0.4-0.20230226180929-6d4760e882f2/exporter.go:85 +0x54c
  github.com/phaag/go-nfdump.(*NfFile).AllRecords.func1()
      go-nfdump@v0.0.4-0.20230226180929-6d4760e882f2/nffile.go:284 +0x228

Previous read at 0x00c0029641f0 by main goroutine:
  github.com/phaag/go-nfdump.(*FlowRecordV3).SamplerInfo()
      go-nfdump@v0.0.4-0.20230226180929-6d4760e882f2/record.go:243 +0x194
  main.nfdumpAllRecords()
      nfdump.go:26 +0x170
  main.main()
      main.go:36 +0x984

Goroutine 20 (running) created at:
  github.com/phaag/go-nfdump.(*NfFile).AllRecords()
      go-nfdump@v0.0.4-0.20230226180929-6d4760e882f2/nffile.go:266 +0xcc
  main.nfdumpAllRecords()
      nfdump.go:23 +0x58
  main.main()
      main.go:36 +0x984
==================
==================
WARNING: DATA RACE
Write at 0x00c0029641e0 by goroutine 20:
  github.com/phaag/go-nfdump.(*NfFile).addExporterStat()
      go-nfdump@v0.0.4-0.20230226180929-6d4760e882f2/exporter.go:86 +0x5ac
  github.com/phaag/go-nfdump.(*NfFile).AllRecords.func1()
      go-nfdump@v0.0.4-0.20230226180929-6d4760e882f2/nffile.go:284 +0x228

Previous read at 0x00c0029641e0 by main goroutine:
  github.com/phaag/go-nfdump.(*FlowRecordV3).SamplerInfo()
      go-nfdump@v0.0.4-0.20230226180929-6d4760e882f2/record.go:243 +0x194
  main.nfdumpAllRecords()
      nfdump.go:26 +0x170
  main.main()
      main.go:36 +0x984

Goroutine 20 (running) created at:
  github.com/phaag/go-nfdump.(*NfFile).AllRecords()
      go-nfdump@v0.0.4-0.20230226180929-6d4760e882f2/nffile.go:266 +0xcc
  main.nfdumpAllRecords()
      nfdump.go:23 +0x58
  main.main()
      main.go:36 +0x984
==================
==================
WARNING: DATA RACE
Write at 0x00c0029641e8 by goroutine 20:
  github.com/phaag/go-nfdump.(*NfFile).addExporterStat()
      go-nfdump@v0.0.4-0.20230226180929-6d4760e882f2/exporter.go:87 +0x60c
  github.com/phaag/go-nfdump.(*NfFile).AllRecords.func1()
      go-nfdump@v0.0.4-0.20230226180929-6d4760e882f2/nffile.go:284 +0x228

Previous read at 0x00c0029641e8 by main goroutine:
  github.com/phaag/go-nfdump.(*FlowRecordV3).SamplerInfo()
      go-nfdump@v0.0.4-0.20230226180929-6d4760e882f2/record.go:243 +0x194
  main.nfdumpAllRecords()
      nfdump.go:26 +0x170
  main.main()
      main.go:36 +0x984

Goroutine 20 (running) created at:
  github.com/phaag/go-nfdump.(*NfFile).AllRecords()
      go-nfdump@v0.0.4-0.20230226180929-6d4760e882f2/nffile.go:266 +0xcc
  main.nfdumpAllRecords()
      nfdump.go:23 +0x58
  main.main()
      main.go:36 +0x984
==================
Native - 77754 records
854.939833ms
Found 3 data race(s)
exit status 66
phaag commented 1 year ago

Comment line 284 in nffile.go as a quick fix. This prevents adding that stat. I will fix it by rearranging the code