When multiple goroutines use different Project instances concurrently,
Go's race detector complains data races.
Issue Detail
schema_helpers.go have some global variables and they are initialized
by setupSchemaLoaders() when validate() and other schema functions
are called for the first time.
However, setupSchemaLoaders() does not have mutex, so some times
multiple gorutines proceed into this function, then a race happens.
Suggested Resolution
We can add a mutex to setupSchemaLoader() to avoid the race condition.
However, the function is supposed to cache results and called not so
many times. Therefore, in this patch, we simply initialize schemas in
init().
(using global variables might be not a good idea. We might want to have some singleton-ish factory or something instead)
Issue Observed
When multiple goroutines use different
Project
instances concurrently, Go's race detector complains data races.Issue Detail
schema_helpers.go
have some global variables and they are initialized bysetupSchemaLoaders()
whenvalidate()
and other schema functions are called for the first time. However,setupSchemaLoaders()
does not have mutex, so some times multiple gorutines proceed into this function, then a race happens.Suggested Resolution
We can add a mutex to
setupSchemaLoader()
to avoid the race condition. However, the function is supposed to cache results and called not so many times. Therefore, in this patch, we simply initialize schemas ininit()
.(using global variables might be not a good idea. We might want to have some singleton-ish factory or something instead)
Appendix
Stack Trace by the race detector: