diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-03-31 10:40:33 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-03-31 10:40:33 +0200 |
commit | 42a4f6f9cbefb56698b9a4274473020188031754 (patch) | |
tree | 8141acf4759f7720048e72db8be62a966a8133a3 /tpl | |
parent | 79b34c2f1e0ba91ff5f4f879dc42eddfd82cc563 (diff) |
tplimpl: Fix map data race in URLLock
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/tplimpl/template_resources.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/tpl/tplimpl/template_resources.go b/tpl/tplimpl/template_resources.go index f10aa72e3..cfec816ad 100644 --- a/tpl/tplimpl/template_resources.go +++ b/tpl/tplimpl/template_resources.go @@ -46,12 +46,17 @@ type remoteLock struct { // URLLock locks an URL during download func (l *remoteLock) URLLock(url string) { + var ( + lock *sync.Mutex + ok bool + ) l.Lock() - if _, ok := l.m[url]; !ok { - l.m[url] = &sync.Mutex{} + if lock, ok = l.m[url]; !ok { + lock = &sync.Mutex{} + l.m[url] = lock } l.Unlock() - l.m[url].Lock() + lock.Lock() } // URLUnlock unlocks an URL when the download has been finished. Use only in defer calls. |