You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func (t*Template) getTemplate(kstring) (*template.Template, bool) {
t.templateMutex.RLock()
defert.templateMutex.RUnlock()
ift.templateMap==nil { // Read done here in other go routine at the same timet.templateMap=make(map[string]*template.Template) // WRITE DONE TO t.templateMap here without read lock
}
v, ok:=t.templateMap[k]
returnv, ok
}
func (t*Template) setTemplate(kstring, v*template.Template) {
t.templateMutex.Lock()
defert.templateMutex.Unlock()
t.templateMap[k] =v
}
Can this be fixed by a simple PR wrapping the assignment of the empty map in a Write Lock (mux.Lock) ?
E.g. like so:
func (t*Template) getTemplate(kstring) (*template.Template, bool) {
t.templateMutex.RLock()
defert.templateMutex.RUnlock()
ift.templateMap==nil {
t.templateMutex.Lock() // Lock prevents other routines from achieving a reader. Maybe add another check to see if it is still nil after getting the Write Lock?defert.templateMutex.Unlock()
t.templateMap=make(map[string]*template.Template)
}
v, ok:=t.templateMap[k]
returnv, ok
}
func (t*Template) setTemplate(kstring, v*template.Template) {
t.templateMutex.Lock()
defert.templateMutex.Unlock()
t.templateMap[k] =v
}
The text was updated successfully, but these errors were encountered:
When running several tests concurrently, the go race detection results in an error in the template writer code:
Can this be fixed by a simple PR wrapping the assignment of the empty map in a Write Lock (
mux.Lock
) ?E.g. like so:
The text was updated successfully, but these errors were encountered: