mithrandie / csvq

SQL-like query language for csv
https://mithrandie.github.io/csvq
MIT License
1.52k stars 64 forks source link

fix(load_view): added mutex to fix data races #124

Open jpa-rocha opened 3 months ago

jpa-rocha commented 3 months ago

fixed data races in our tests

mithrandie commented 3 months ago

My understanding is that the variables assigned within the two added sync.Mutex.Lock regions in the function readRecordSet are assigned only within their respective threads. Can you please explain which variables and what kind of data race occurs?

jpa-rocha commented 3 months ago

Hi thanks for getting back to me. It seems the problem is the pos variable that is declared in the readRecordSet function, and then accessed by the 2 go functions in it.

WARNING: DATA RACE                                                                                                                                                                                                                            
Read at 0x00c0001da838 by goroutine 17:                                                                                                                                                                                                       
  github.com/mithrandie/csvq/lib/query.readRecordSet.func1()                                                                                                                                                                                  
      /home/jrocha/kerouac/vendor/github.com/mithrandie/csvq/lib/query/load_view.go:1343 +0x1f9                                                                                                                                               

Previous write at 0x00c0001da838 by goroutine 18:                                                                                                                                                                                             
  github.com/mithrandie/csvq/lib/query.readRecordSet.func2()                                                                                                                                                                                  
      /home/jrocha/kerouac/vendor/github.com/mithrandie/csvq/lib/query/load_view.go:1392 +0x4c4                   

In our tests, when the file opened only has one entry the data race doesnt happen, but more than one will trigger it.