From d2e8c5f773a39f9e4a87d5ac38b7ef7923e795a0 Mon Sep 17 00:00:00 2001 From: Matthew Jaffee Date: Tue, 20 Jul 2021 10:36:17 -0500 Subject: [PATCH] fix other batch client rowCache race --- client/batch.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/batch.go b/client/batch.go index e94cd73c2..75a0cf366 100644 --- a/client/batch.go +++ b/client/batch.go @@ -824,6 +824,8 @@ func (b *Batch) doTranslation() error { rowCache = make(map[string]agedTranslation) b.rowTranslations[fieldName] = rowCache } + // create a lock since we're updating this concurrently below + rowCacheLock := &sync.Mutex{} i, tt := i, tt eg.Go(func() error { @@ -845,12 +847,14 @@ func (b *Batch) doTranslation() error { b.log.Debugf("translating %d field keys for %s took %v", len(trans), fieldName, time.Since(start)) // Apply keys to translation cache. + rowCacheLock.Lock() for key, id := range trans { rowCache[key] = agedTranslation{ id: id, lastUsed: b.cycle, } } + rowCacheLock.Unlock() switch ftype := field.Opts().Type(); ftype { case FieldTypeSet, FieldTypeMutex, FieldTypeTime: