i18n: Prevent data race in lang code handling
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 4 Nov 2017 08:43:35 +0000 (09:43 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 4 Nov 2017 09:48:29 +0000 (10:48 +0100)
See #3564

i18n/i18n.go
i18n/translationProvider.go

index 73417fb3240cdb32c9b7f12bea2c47e643be2d69..6cc3d0b3388ddcde99ed07e160432a64fbb5b7c0 100644 (file)
@@ -68,7 +68,9 @@ func (t Translator) initFuncs(bndl *bundle.Bundle) {
                currentLang := lang
 
                t.translateFuncs[currentLang] = func(translationID string, args ...interface{}) string {
+                       tpMu.RLock()
                        tFunc, err := bndl.Tfunc(currentLang)
+                       tpMu.RUnlock()
                        if err != nil {
                                jww.WARN.Printf("could not load translations for language %q (%s), will use default content language.\n", lang, err)
                        }
index 663a8dd5e0d15dff82af971e4047f96c4e4d78e3..556ee7a925e917050752db183cbba78ec3f4f5be 100644 (file)
@@ -25,7 +25,7 @@ import (
 
 // Unfortunately this needs to be global, see
 // https://github.com/nicksnyder/go-i18n/issues/82
-var tpMu sync.Mutex
+var tpMu sync.RWMutex
 
 // TranslationProvider provides translation handling, i.e. loading
 // of bundles etc.