Race condition if multiple threads are parsing CSV and somebody calls SetHeaderNormalizer
brianV opened this issue · comments
Brian Vuyk commented
Hi all.
We've noted a race condition with SetHeaderNormalizer()
:
func SetHeaderNormalizer(f Normalizer) {
normalizeName = f
// Need to clear the cache hen the header normalizer changes.
structInfoCache = sync.Map{}
}
If we have threads currently working and performing operations on structInfoCache
, our copying of a blank map into structInfoCache
leads to various errors including:
fatal error: sync: unlock of unlocked mutex
structInfoCache
should be defined as a *sync.Map{}
. When we need to clear the cache, we then should run:
structInfoCache = &sync.Map{}
In-progress calls to the old structInfoCache
would complete, and new calls will operate against the new one.