csvq icon indicating copy to clipboard operation
csvq copied to clipboard

fix(load_view): added mutex to fix data races

Open jpa-rocha opened this issue 1 year ago • 3 comments

jpa-rocha avatar Jul 25 '24 10:07 jpa-rocha

fixed data races in our tests

jpa-rocha avatar Jul 25 '24 10:07 jpa-rocha

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?

mithrandie avatar Jul 28 '24 17:07 mithrandie

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.

jpa-rocha avatar Jul 29 '24 06:07 jpa-rocha